-
Notifications
You must be signed in to change notification settings - Fork 441
Closed
Milestone
Description
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.