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

Variable names used when reporting options in exceptions text #185

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

Variable names used when reporting options in exceptions text #185

AlexFalappa opened this issue Sep 21, 2017 · 2 comments

Comments

@AlexFalappa
Copy link

Consider the following, purposely atypical, example:

public class App {

    public static void main(String[] args) {
        CmdLineArgs cla = new CmdLineArgs();
        CommandLine cl = new CommandLine(cla);
        try {
            cl.parse(args);
            System.out.println(cla.foo.getAbsolutePath());
            System.out.println(cla.bar.getAbsolutePath());
        } catch (CommandLine.ParameterException pe) {
            System.err.println(pe.getMessage());
            CommandLine.usage(cla, System.out);
        }

    }

}

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

    @CommandLine.Parameters(arity = "1", paramLabel = "IN_FILE", description = "The input file")
    File foo;

    @CommandLine.Option(names = "-o", paramLabel = "OUT_FILE", description = "The output file", required = true)
    File bar;
}

When launched without arguments produces:

Missing required options [bar, foo]
Usage: app -o=OUT_FILE IN_FILE
      IN_FILE                 The input file
  -o= OUT_FILE                The output file

As you can see there are little cues for an user to link the variable names used in the exception text to the usage message.

It would be better to use the paramLabel string, if available, or, in the case of options, one of the names strings and to use the variable name as fallback.

@remkop
Copy link
Owner

remkop commented Sep 21, 2017

Thank you for raising this!
I agree: the error message should be consistent with the usage message.
I like your suggestions for fixing this.

@remkop remkop added this to the 1.1.0 milestone Sep 21, 2017
@remkop remkop modified the milestones: 2.0.0, 2.?.0 polishing Sep 28, 2017
@remkop remkop closed this as completed in 39f1944 Oct 1, 2017
@remkop
Copy link
Owner

remkop commented Oct 1, 2017

I made a number of improvements in this area.
For the example above, the error message is now:

Missing required options [-o=OUT_FILE, params[*]=IN_FILE]

Please verify.

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