Hi Gilles,

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.

This is possible by declaring the foo option with exactly one argument. Here is an example:

    Options options = new Options();
    options.addOption(OptionBuilder.hasArg().create("foo"));

CommandLine cmd = new GnuParser().parse(options, new String[] { "--foo", "a", "--foo", "b", "--foo", "c", "cmdArg1", "cmdArg2"});

    String[] values = cmd.getOptionValues("foo");


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

By using quotes the value 'a b c' is kept as is, the parser will never try to split it. If the argument was a path containing a space you certainly wouldn't want to split the value.

Emmanuel Bourg



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

Reply via email to