commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Cardenas (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CLI-288) Inconsistent parsing of unlimited option values
Date Sun, 01 Jul 2018 16:16:00 GMT
Adam Cardenas created CLI-288:
---------------------------------

             Summary: Inconsistent parsing of unlimited option values
                 Key: CLI-288
                 URL: https://issues.apache.org/jira/browse/CLI-288
             Project: Commons CLI
          Issue Type: Bug
          Components: Parser
    Affects Versions: 1.4
            Reporter: Adam Cardenas


with the following configuration...
{code:java}
DefaultParser parser = new DefaultParser();
 Options opts = new Options();

Option pager = Option.builder(null)
 .longOpt("cmd")
 .hasArg()
 .numberOfArgs(Option.UNLIMITED_VALUES)
 .build();

opts.addOption(pager);
{code}
 
This works as long as the value of *cmd* is a single value.
{code}
$ myApp --cmd='less'
{code}

The following does not work, as soon as we add options to less
{code}
$ myApp --cmd='less -XFR'
Exception in thread "main" com.cevaris.ag4j.cli.AppArgsException: org.apache.commons.cli.UnrecognizedOptionException:
Unrecognized option: -XFR
        at com.cevaris.ag4j.cli.ApacheAppArgs.parse(ApacheAppArgs.java:33)
        at com.cevaris.ag4j.Main.main(Main.java:61)
Caused by: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -XFR
        at org.apache.commons.cli.DefaultParser.handleUnknownToken(DefaultParser.java:360)
        at org.apache.commons.cli.DefaultParser.handleConcatenatedOptions(DefaultParser.java:702)
        at org.apache.commons.cli.DefaultParser.handleShortAndLongOption(DefaultParser.java:533)
        at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:243)
        at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:120)
        at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:76)
        at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:60)
        at com.cevaris.ag4j.cli.ApacheAppArgs.parse(ApacheAppArgs.java:31)'
{code}

The following works, as long as we use a space to separate option & value, rather than
using an *=*
{code}
$ myApp --cmd 'less -XFR'  # works
$ myApp --cmd='less -XFR'  # fails
{code}

Attempted to use *.valueSeparator()* with no luck.




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message