You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Todd Ye (Jira)" <ji...@apache.org> on 2020/12/17 17:18:00 UTC
[jira] [Created] (CLI-306) Issue parsing numeric options following
an option which accepts multiple args
Todd Ye created CLI-306:
---------------------------
Summary: Issue parsing numeric options following an option which accepts multiple args
Key: CLI-306
URL: https://issues.apache.org/jira/browse/CLI-306
Project: Commons CLI
Issue Type: Bug
Components: CLI-1.x
Affects Versions: 1.4
Reporter: Todd Ye
commons-cli seems be unable be unable to detect numeric options in their short "opt" form following an option which takes multiple arguments.
Will consistently throw:
{code:java}
Exception in thread "main" org.apache.commons.cli.MissingOptionException: Missing required option: 2
{code}
How to reproduce:
{code:java}
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()));
}
{code}
now pass in:
{code:java}
--one argNumOne,argNumTwo -2 argNumThree
{code}
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:
{code:java}
--one argNumOne,argNumTwo --two argNumThree
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)