Better Error Message When Using Multiple Commands

30 views
Skip to first unread message

Robert Laks

unread,
Apr 5, 2017, 4:18:50 PM4/5/17
to jcommander
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.


Cédric Beust ♔

unread,
Apr 5, 2017, 4:20:54 PM4/5/17
to jcommander
This makes sense, can you file an issue?

Thanks!

-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Laks

unread,
Apr 5, 2017, 4:39:24 PM4/5/17
to jcommander, ced...@beust.com

-- 
Cédric


To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+...@googlegroups.com.

Cédric Beust ♔

unread,
Apr 5, 2017, 5:21:12 PM4/5/17
to jcommander
Thanks!

-- 
Cédric


To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages