AbstractCommand decides whether the user asked for help by looking only at the option names typed on the command line, never at what the command declares. Two defects follow from that.
@Command(name = "connect", description = "Connect to a host", help = "Help of 'connect'")
public void connect(@Option(shortName = 'h', longName = "host") String host, @Option String port) {
System.out.println("connecting to host=" + host + " port=" + port);
}
1. A declared -h is hijacked as help
isHelp() treats any option with shortName == 'h' as a help request. The parser resolves the value correctly and execute() then discards it, so the command never runs - and the exit status is OK, so it fails silently:
shell:>connect -h myhost
Help of 'connect' <-- expected: connecting to host=myhost
shell:>connect --host myhost
connecting to host=myhost port=null <-- the same option, spelled long, works
(The third line in the screenshot above is explained in the last section.)
2. Help is only honoured when it is the sole option
The dispatch condition is options.size() == 1 && isHelp(...), so anything else on the line suppresses it:
shell:>connect --help=true
Help of 'connect'
shell:>connect --help=true --port 22
connecting to host=null port=22 <-- expected: Help of 'connect'
These cannot be fixed separately
options.size() == 1 is what currently masks defect 1 (the third line of the first screenshot):
shell:>connect -h myhost --port 22
connecting to host=myhost port=22 <-- correct today, only because size() == 2
Relax the dispatch on its own and that line prints help instead, widening defect 1 from one option to any number. A change fixing only defect 2 is therefore a regression.
Reproduced on main.
AbstractCommanddecides whether the user asked for help by looking only at the option names typed on the command line, never at what the command declares. Two defects follow from that.1. A declared
-his hijacked as helpisHelp()treats any option withshortName == 'h'as a help request. The parser resolves the value correctly andexecute()then discards it, so the command never runs - and the exit status isOK, so it fails silently:(The third line in the screenshot above is explained in the last section.)
2. Help is only honoured when it is the sole option
The dispatch condition is
options.size() == 1 && isHelp(...), so anything else on the line suppresses it:These cannot be fixed separately
options.size() == 1is what currently masks defect 1 (the third line of the first screenshot):Relax the dispatch on its own and that line prints help instead, widening defect 1 from one option to any number. A change fixing only defect 2 is therefore a regression.
Reproduced on
main.