You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2007/10/27 20:41:50 UTC

[jira] Updated: (CLI-145) ArgumentBuilder.withMaximum causes parse errors: Unexpeced while processing options

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

Henri Yandell updated CLI-145:
------------------------------

        Fix Version/s: 2.0
    Affects Version/s:     (was: 2.0)

> ArgumentBuilder.withMaximum causes parse errors: Unexpeced <value> while processing options
> -------------------------------------------------------------------------------------------
>
>                 Key: CLI-145
>                 URL: https://issues.apache.org/jira/browse/CLI-145
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-2.x
>         Environment: Windows XP
>            Reporter: David Biesack
>             Fix For: 2.0
>
>         Attachments: CLI145.patch
>
>
> With the sample program below, running with the arguments
>   -a 0 -b 1 2 3 4
> causes the error:
> Unexpected 3 while processing options                                           
> Usage:                                                                          
>  [-a <a1> [<a2> ...] -b <b1> <b2> [<b3> [<b4>]]]                                
> options                                                                         
>   -a (--a) a [a ...]                                                            
>   -b (--b) b b [b [b]]                                                          
> I specified .withMinimum(2).withMaximum(4) 
> The help is correct, but the value '3' is not added as a value.
> Note also that if for bOption, if you add two more defaults (uncomment them in the source)
>             .withDefault("10000")
>             .withDefault("1000000")
> an error is raised (incorrectly) on the first b value (i.e. 1 instead of 3) :
> Unexpected 1 while processing options         
> Usage:                                                                          
>  [-a <a1> [<a2> ...] -b <b1> <b2> [<b3> [<b4>]]]                                
> options                                                                         
>   -a (--a) a [a ...]                                                            
>   -b (--b) b b [b [b]]
> Source:
> package org.apache.commons.cli2.issues;
> import java.util.List;
> import org.apache.commons.cli2.CommandLine;
> import org.apache.commons.cli2.Group;
> import org.apache.commons.cli2.builder.ArgumentBuilder;
> import org.apache.commons.cli2.builder.DefaultOptionBuilder;
> import org.apache.commons.cli2.builder.GroupBuilder;
> import org.apache.commons.cli2.commandline.Parser;
> import org.apache.commons.cli2.option.DefaultOption;
> public class WithMinimum
> {
>    public static void main(String[] args)
>    {
>       final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
>       final ArgumentBuilder abuilder = new ArgumentBuilder();
>       final GroupBuilder gbuilder = new GroupBuilder();
>       DefaultOption aOption = obuilder//
>             .withShortName("a")
>             .withLongName("a")
>             .withArgument(abuilder
>                   .withName("a")
>                   .withDefault("10")
>                   .create())
>             .create();
>       DefaultOption bOption = obuilder
>       .withShortName("b")
>       .withLongName("b")
>       .withArgument(abuilder
>             .withName("b")
>             .withMinimum(2)
>             .withMaximum(4)
>             .withDefault("100")
>             .withDefault("1000")
> //            .withDefault("10000")
> //            .withDefault("1000000")
>             .create())
>       .create();
>       Group options = gbuilder
>             .withName("options")
>             .withOption(aOption)
>             .withOption(bOption)
>             .create();
>       Parser parser = new Parser();
>       parser.setHelpTrigger("--help");
>       parser.setGroup(options);
>       CommandLine cl = parser.parseAndHelp(args);
>       if (cl == null)
>          System.exit(1);
>       int a = Integer.parseInt(cl.getValue(aOption).toString());
>       List b = cl.getValues(bOption);
>       System.out.printf("a=%d b=%s%n", a, b);
>    }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.