jcommander
jcommander copied to clipboard
Better Error Message When Using Multiple Commands
I have a CLI parser that is using JCommander. Overall I'm pretty happy with the results, but I've got an issue where the error message that is specified is when two command names are provided in the CLI is a little misleading. See example below:
./SampleApp -v command2 -o someOutputDir command1
ERROR: Was passed main parameter 'command1' but no main parameter was defined
Usage: SampleApp [options] [command] [command options]
Options:
-h, --help
Prints out usage documentation.
Default: false
-v, --verbose
Prints execution steps and verification info.
Default: false
Commands:
command1 Description for command1.
Usage: command1 [options]
Options:
-et, --endTime
End time in UTC.
command2 Description for command2
Usage: command2 [options]
Options:
* -o, --outputDirectory
Directory to place output files.
In my case neither command has a main parameter, so when the second command is supplied it looks like JCommander attempts to treat it as a main parameter but cannot find a main parameter to apply it to. I'd prefer to see a little extra work and have JCommander attempt to find a command name/alias that this argument matches and if found displays an error message stating that only one command may be supplied.
+1