commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Thomas <greg.d.tho...@gmail.com>
Subject [CLI] - withValueSeparator() usage
Date Fri, 01 Feb 2013 15:03:38 GMT
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