RFR: 1275: An unknown sub-command gives a confusing error message [v3]

Erik Joelsson erikj at openjdk.java.net
Wed Dec 15 22:43:05 UTC 2021


On Wed, 15 Dec 2021 12:46:51 GMT, Guoxiong Li <gli at openjdk.org> wrote:

>> Hi all,
>> 
>> When using the unknown command, the client will output the unexpected message. For example:
>> 
>> 
>> $ git-pr lis 123
>> 
>> error: unexpected input: 123
>> usage: git-pr [options] [<COMMAND>]
>> 	-h, --help      Show help
>> 	    --verbose   Turn on verbose output
>> 	    --debug     Turn on debugging output
>> 	    --version   Print the version of this tool
>> 
>> 
>> When the client can't identify the sub-command `git-pr lis`, it will execute the default command `git-pr help` and will pass `lis 123` as the argument to the `git-pr help` command. And the `git-pr help` can resolve only one argument, which is `lis` in this example, so it would output `error: unexpected input: 123`.
>> 
>> This patch will output more information to the user:
>> 
>> 
>> $ git-pr lis 123
>> 
>> Can't find the sub-command 'lis', the default sub-command 'help' will be executed.
>> The arguments [lis, 123] will be passed to the default sub-command.
>> 
>> error: unexpected input: 123
>> usage: git-pr [options] [<COMMAND>]
>> 	-h, --help      Show help
>> 	    --verbose   Turn on verbose output
>> 	    --debug     Turn on debugging output
>> 	    --version   Print the version of this tool
>> 
>> 
>> The added information can let the user know why the following output is shown.
>> 
>> Thanks for taking the time to review.
>> 
>> Best Regards,
>> -- Guoxiong
>
> Guoxiong Li has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
> 
>  - Merge branch 'master' into SKARA-1275
>  - Adjust the message. Excluded the 'git-webrev'.
>  - 1275: The unknown sub-command will ouput the unexpected message

args/src/main/java/org/openjdk/skara/args/MultiCommandParser.java line 65:

> 63:                 return () -> p.main(forwardedArgs);
> 64:             }
> 65:             if (!"git-webrev".equals(programName) && !"git webrev".equals(programName)) {

I was expecting a more elegant solution to this. I would add a property/method on the Command interface that  MutliCommandParser can use to check this. Something like Command::defaultCommandExpected.

-------------

PR: https://git.openjdk.java.net/skara/pull/1257


More information about the skara-dev mailing list