Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.4
-
None
-
None
Description
commons-cli seems to be unable to detect numeric options in their short "opt" form following an option which takes multiple arguments.
Will consistently throw:
Exception in thread "main" org.apache.commons.cli.MissingOptionException: Missing required option: 2
How to reproduce:
Option multipleOptional = Option.builder("1") .longOpt("one") .argName("value1,value2,...,valueN") .hasArgs() .valueSeparator(',') .build(); Option singleMandatory = Option.builder("2") .argName("value") .longOpt("two") .hasArg() .required() .build(); Options options = new Options(); options.addOption(singleMandatory); options.addOption(multipleOptional); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); for (Option o : line.getOptions()) { System.out.println(o.getOpt() + '\t' + Arrays.toString(o.getValues())); }
now pass in:
--one argNumOne,argNumTwo -2 argNumThree
Note that an error will not occur if "opt" is set to a char like "a/b/c" or if the previous option is set with hasArg() instead of hasArgs()
Also error will not occur if the longOpt is used such as:
--one argNumOne,argNumTwo --two argNumThree