You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michael Osipov (JIRA)" <ji...@apache.org> on 2016/07/18 19:45:20 UTC

[jira] [Updated] (CLI-255) DefaultParser, option with long name and single dash, unlimited arguments

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

Michael Osipov updated CLI-255:
-------------------------------
    Description: 
If I have options with long name and single hyphen, 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:

{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}


> 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 hyphen, 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)