Hello.

> I only offer the code to illustrate how to deal with repeated options.  In
> this particular case, the repeated option is -N with
> values "1=localhost:8000", "2=localhost:8001" etc (these values relate to
> the particular application I'm developing).

I understood that. I'm just stressing that it's not your code that is
problematic but that IIUC the CLI is forcing me to call my application like
  $ cmd --foo 1=a --foo 2=b --foo 3=c
which, in my case, is totally unnatural because "1", "2" and "3" have no
meaning; they are not properties of anything.

Regards,
Gilles

> > > 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".

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to