commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Neidhart <thomas.neidh...@gmail.com>
Subject Re: [CLI] - withValueSeparator() usage
Date Tue, 05 Feb 2013 09:17:15 GMT
On Sun, Feb 3, 2013 at 9:56 PM, Thomas Neidhart
<thomas.neidhart@gmail.com>wrote:

> On 02/03/2013 06:29 PM, Greg Thomas wrote:
> > I've had a look; I the only place that could do with clarification is
> > the javadoc for getOptionValues @
> >
> http://commons.apache.org/cli/api-release/org/apache/commons/cli/CommandLine.html#getOptionValues(java.lang.String)
> > /
> http://commons.apache.org/cli/api-release/org/apache/commons/cli/CommandLine.html#getOptionValues(char)
> >
> > Currently, both say:
> >
> > "Retrieves the array of values, if any, of an option."
> >
> > I'd suggest something like;
> >
> > Where a valueSeparator is used to separate two argument values, these
> > will return both values in an array of length 2.
> > @see OptionBuilder#withValueSeparator()
>
> I think the examples provided in OptionBuilder#withValueSeparator() and
> OptionBulder#withValueSeparator(char) should be improved to clearly
> indicate that this separator is only used to distinguish between key and
> value, and not to split values itself.
>

I did look further into this issue, and

The value separator is only used in the Option#processValue method and is
indeed used to split the argument into multiple values.
Now, the splitting is only performed if in the OptionBuilder, the hasArgs()
is specified with the number of expected argument values.
With the default setting of hasArg(), like in the example above, no
splitting will be performed.

The example above also worked, because the option and arguments are
separated by whitespace and thus provided as separate tokens to the parser.
In this case, the argument is always the next token, regardless of the
separator. If you would specify hasArgs(3), you would indeed get the values
split into an array of 3 strings.

Thomas

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message