commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Speirs <wspe...@apache.org>
Subject Re: [CLI] - withValueSeparator() usage
Date Fri, 01 Feb 2013 15:17:07 GMT
I don't think that's how option values works. Option values is basically
like Java prefs: -Dkey=value. I'm a bit surprised it doesn't return b,c as
the value.

I did a blog post here on CLI, maybe the examples are more helpful (full
source linked at the end):
http://www.sop4j.com/2013/01/parsing-command-line.html

Bill-


On Fri, Feb 1, 2013 at 10:03 AM, Greg Thomas <greg.d.thomas@gmail.com>wrote:

> I'm struggling on how to use the withValueSeparator() option;
>
> Taking the following piece of code ...
>
> Options options = new Options();
> Option columns = OptionBuilder
>                             .hasArg()
>                             .withArgName("CSV columns")
>                             .withValueSeparator(',')
>                             .withDescription("Specify the comma separated
> list of columns")
>                             .create("columns");
> options.addOption(columns);
>
> CommandLineParser parser = new GnuParser();
> CommandLine line = parser.parse(options, new String[]{ "-columns",
> "a,b,c"});
> System.out.println("hasOption:" + line.hasOption("columns"));
> System.out.println("column count:" +
> line.getOptionValues("columns").length);
>
> I woudl expect it to print out something like:
> hasOption:true
> column count:3
>
> whereas in fact I'm getting
> hasOption:true
> column count:1
>
> i.e. despite me specifying ',' as a value separator, getOptionValues() is
> returning a array that is one element in size, containing "a,b,c" instead
> of three elements, each containing a single letter.
>
> I'm missing something - what it is?
>
> Thanks,
>
> Greg
>

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