Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing usage message for collection options #186

Closed
AlexFalappa opened this issue Sep 21, 2017 · 3 comments
Closed

Confusing usage message for collection options #186

AlexFalappa opened this issue Sep 21, 2017 · 3 comments
Milestone

Comments

@AlexFalappa
Copy link

The following test app:

@CommandLine.Command(name = "app")
public class App {

    @CommandLine.Option(names = "-n", paramLabel = "NAME", description = "list of names", type = String.class/*, arity = "1..*"*/)
    List<String> names = new LinkedList<>();

    public static void main(String[] args) {
        App app = new App();
        CommandLine cl = new CommandLine(app);
        cl.usage(System.out);
    }

}

Produces:

Usage: app [-n[=NAME...]]
  -n= =NAME...]               list of names

It would be better something like this:

Usage: app [-n[=NAME...]]
  -n= [NAME [NAME...]]               list of names

Interestingly uncommenting the arity specification produces a better usage:

Usage: app [-n=NAME [NAME...]]
  -n= NAME [NAME...]          list of names
@remkop
Copy link
Owner

remkop commented Sep 21, 2017

Oops. This is a bug. Thanks for letting me know!

@remkop remkop added this to the 1.1.0 milestone Sep 21, 2017
@remkop remkop closed this as completed in a832eee Sep 30, 2017
@remkop
Copy link
Owner

remkop commented Sep 30, 2017

Fixed in master, please confirm.
After this change, the usage message will be as below because of the changes made for #192:

Usage: app [-n=NAME]...
  -n= NAME                    list of names

The #192 change means that multi-value options (array, list, map fields) no longer greedily consume arguments. They just consume 1 arg by default. If the user wants to specify multiple values they need to specify the option multiple times:

app -n AAA -n BBB -n CCC

With arity uncommented (meaning that every -n option can be followed by one or more NAMEs), the usage looks like this:

Usage: app [-n=NAME...]...
  -n= NAME...                 list of names

@AlexFalappa
Copy link
Author

I won't have a chance to try your latest improvements right now, sorry. I will try my best next week.

However I like the change made for #192, an option consuming multiple arguments is confusing and should be avoided in favor of specifying that option more than once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants