What is the best way to support a command line option that occurs multiple
times in a single command line invocation?
(I did some web searching with no ideal solution to this, but I appologize
if this is a recurring issue on this list. I just subscribed...)
For example, if I want to set the debug level for several different classes
like this:
myProgram -d com.mycompany.etrace.filters.udp.UdpPacketDistributor=TRACE
-d com.mycompany.etrace.filters.udp.SomOtherClass=DEBUG
I have used the OptionBuilder, but it doesn't seem to work the way I expect:
CommandLineParser parser = new BasicParser();
Options options = new Options();
Option debug = OptionBuilder.withArgName("className=level")
.hasArgs()
.withValueSeparator()
.withDescription("debug level")
.create('d');
options.addOption(debug);
Then when I parse the command line:
if (commandLine.hasOption('d'))
{
String[] debugOptArray = commandLine.getOptionValues('d');
for (String str: debugOptArray)
{
LOGGER.debug("str: " + str);
}
}
I get
2009-02-17 13:28:33,985 DEBUG EtraceCommand.java - str:
com.comcast.etrace.filters.udp.UdpPacketDistributor
2009-02-17 13:28:34,782 DEBUG EtraceCommand.java - str: TRACE
2009-02-17 13:28:36,095 DEBUG EtraceCommand.java - str:
com.comcast.etrace.filters.udp.SomOtherClass
2009-02-17 13:28:37,454 DEBUG EtraceCommand.java - str: DEBUG
2009-02-17 13:28:39,876 DEBUG EtraceCommand.java - debug string:
com.comcast.etrace.filters.udp.UdpPacketDistributor
It's not deterministic as far as where in the debugOptArray the className is
and the level are, respectively.
Is there a way to extract all the "className" elements and the associated
"level" elements. A sort of Map interface?
Thanks.
--
- Ed