Skip to content

Composite Argument Groups: more informative error messages #744

@deining

Description

@deining

I'm using the following code to ilustrate the issue:

package test;

import java.util.List;

import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

public class ArgGroupsTest {

    public static void main(String[] args) {
        CommandLine cmd = new CommandLine(new TestCommand());
        cmd.execute( "-v");
    }

    @Command(name = "ArgGroupsTest")
    static class TestCommand implements Runnable {

        @ArgGroup( exclusive = false, multiplicity = "2..3")
        List<DataSource> datasource;

        static class DataSource {
            @Option(names = "-v", required = true)
            static boolean aString;
        }

        @Override
        public void run() {
            // nothing to do here
        }
    }
}

Issue 1: If I'm running the code above with one argument only ("-v"), I'm getting an error message:

Error: Group: (-v) (-v) [-v] must be specified 2 times but was matched 1 times
Usage: ArgGroupsTest (-v) (-v) [-v]
  -v

In general, the message is fine, however, there is still room for improvement: it's the group ('-v') that needs to be specified at least two times, currently, the message tells that you have to give (-v) (-v) [-v] three times, however. This is misleading IMHO, I would propose to come up with an error message like:

Error: Group (-v) was found only once, must be specified 2 times at least 
Usage: ArgGroupsTest (-v) (-v) [-v]
  -v

Issue 2: If I'm running the code with four arguments ("-v -v -v -v"), I'm getting an error message, too:

Error: expected only one match but got (-v) (-v) [-v]={-v -v -v} and (-v) (-v) [-v]={-v}
Usage: ArgGroupsTest (-v) (-v) [-v]
  -v

I doubt whether this makes clear to the user what's wrong here.
In this case, I would propose to come up with an error message like:

Error: Group (-v) was found 4 times, must not be given more than 3 times
Usage: ArgGroupsTest (-v) (-v) [-v]
  -v

Just my 2 cents, thanks for providing and continuously improving picocli.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions