commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CLI-255) DefaultParser, option with long name and single dash, unlimited arguments
Date Sun, 28 Jun 2015 09:10:04 GMT

     [ https://issues.apache.org/jira/browse/CLI-255?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Benedikt Ritter updated CLI-255:
--------------------------------
    Description: 
If I have options with long name and single dash, DefaultParser does not recognize them after
a list of unlimited arguments.
Here is the test case:

{code:java}
    public void testUnlimitedArgs() throws Exception
    {
        String[] args = new String[] {"-unlimitedOne", "one", "two", "-unlimitedTwo", "alpha"};

        Options options = new Options();
        options.addOption(Option.builder("unlimitedOne").hasArgs().build());
        options.addOption(Option.builder("unlimitedTwo").hasArgs().build());

        CommandLine cl = parser.parse(options, args);

        assertTrue("Confirm -unlimitedOne is set", cl.hasOption("unlimitedOne"));
        assertEquals("number of arg for -unlimitedOne", 2, cl.getOptionValues("unlimitedOne").length);
        assertTrue("Confirm -unlimitedTwo is set", cl.hasOption("unlimitedTwo"));
        assertEquals("number of arg for -unlimitedTwo", 1, cl.getOptionValues("unlimitedTwo").length);
    }
{code}

  was:
If I have options with long name and single dash, DefaultParser does not recognize them after
a list of unlimited arguments.
Here is the test case:
---------------------------
    public void testUnlimitedArgs() throws Exception
    {
        String[] args = new String[] {"-unlimitedOne", "one", "two", "-unlimitedTwo",
"alpha"};

        Options options = new Options();
        options.addOption(Option.builder("unlimitedOne").hasArgs().build());
        options.addOption(Option.builder("unlimitedTwo").hasArgs().build());

        CommandLine cl = parser.parse(options, args);

        assertTrue("Confirm -unlimitedOne is set", cl.hasOption("unlimitedOne"));
        assertEquals("number of arg for -unlimitedOne", 2,
cl.getOptionValues("unlimitedOne").length);
        assertTrue("Confirm -unlimitedTwo is set", cl.hasOption("unlimitedTwo"));
        assertEquals("number of arg for -unlimitedTwo", 1,
cl.getOptionValues("unlimitedTwo").length);
    }


> DefaultParser, option with long name and single dash, unlimited arguments
> -------------------------------------------------------------------------
>
>                 Key: CLI-255
>                 URL: https://issues.apache.org/jira/browse/CLI-255
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.3, 1.3.1
>            Reporter: Alexander Prishchepov
>            Priority: Minor
>
> If I have options with long name and single dash, DefaultParser does not recognize them
after a list of unlimited arguments.
> Here is the test case:
> {code:java}
>     public void testUnlimitedArgs() throws Exception
>     {
>         String[] args = new String[] {"-unlimitedOne", "one", "two", "-unlimitedTwo",
"alpha"};
>         Options options = new Options();
>         options.addOption(Option.builder("unlimitedOne").hasArgs().build());
>         options.addOption(Option.builder("unlimitedTwo").hasArgs().build());
>         CommandLine cl = parser.parse(options, args);
>         assertTrue("Confirm -unlimitedOne is set", cl.hasOption("unlimitedOne"));
>         assertEquals("number of arg for -unlimitedOne", 2, cl.getOptionValues("unlimitedOne").length);
>         assertTrue("Confirm -unlimitedTwo is set", cl.hasOption("unlimitedTwo"));
>         assertEquals("number of arg for -unlimitedTwo", 1, cl.getOptionValues("unlimitedTwo").length);
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message