Hi.
> I had a similar problem, where I wanted a series of command-line arguments
> to be like
> -N1=localhost:8000 -N2=localhost:8001 -N3=localhost:8002 etc.
>
> The code below allowed me to get all the -N args values as an enumeration,
> and is based on some code I found in the documentation.
> Hope it makes sense and is useful.
It makes sense, but it's just a workaround that makes you use "dummy"
properties (i.e. you don't need things like "1", "2", "3" in the code).
Moreover, it is error-prone because one could easily and mistakenly write
-N1=localhost:8000 -N1=localhost:8001 -N3=localhost:8002
which would probably make one of the arguments disappear silently.
I think that the simpler syntax
-N localhost:8000 -N localhost:8001 -N localhost:8002
should be allowed, and behave as expected, i.e. IMHO one should be able to
retrieve the String[] array with
String[] nodes = cli.getOptionValues("N");
If it is not possible, shouldn't it be considered a bug?
Best,
Gilles
> Regards
>
> -- Simon
>
> Option node =
> OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator()
> .withDescription("brokerid=address").create("N");
> options.addOption(node);
> CommandLineParser parser = new GnuParser();
> CommandLine cli = parser.parse(options,args);
> Properties props = cli.getOptionProperties("N");
> for (Enumeration keys = props.keys();keys.hasMoreElements();) {
> String key = (String) keys.nextElement();
> String[] address = props.getProperty(key).split(":");
> NodeInfo n = new
> NodeInfo(Integer.parseInt(key),address[0],Integer.parseInt(address[1]));
> cfg.addNode(n);
> }
>
> On Tue, May 24, 2011 at 2:13 PM, Gilles Sadowski <
> [email protected]> wrote:
>
> > Hello.
> >
> > [With official release 1.2]
> >
> > I'd like to call a commmand "cmd" as follows:
> > $ cmd --foo a --foo b --foo c cmdArg1 cmdArg2
> >
> > There can be any number of arguments to the option "--foo". When I try,
> > the parser ("GnuParser") considers the "cmdArg1" and "cmdArg2" arguments as
> > arguments to the "--foo" option.
> > This is so even with the "stopAtNonOption" flag set to true.
> >
> > When I try
> > $ cmd --foo 'a b c' cmdArg1 cmdArg2
> > I don't get 3 separate option arguments "a", "b", "c", but a single string
> > "a b c".
> >
> >
> > Best regards,
> > Gilles
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]