NI-hao, I think you misinterpreted the argument creation, just declare the dynamic option once:
Option property = OptionBuilder.withArgName( "property=value" ) .hasArgs(2) .withValueSeparator() .withDescription( "use value for given property" ) .create( "D" ); The once obtained the CommandLine instance, invoke the getOptionProperties()[1] method: Properties dynaProperties = commandLine.getOptionProperties( "D" ); HTH! -Simo [1] http://commons.apache.org/cli/api-release/org/apache/commons/cli/CommandLine.html#getOptionProperties(java.lang.String) http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ 2011/12/24 LvXiaoyi <mrl...@hotmail.com>: > > > > > Hi, > I want to use CLI (version 1.2) to parse Java like properties, > ie. java -DnodeName=MyServer -DnodeIp=10.1.2.2 -DnodePort=1003 > > here is my test code: > Option helpOp = new Option("h", "command line help"); > > Option nodeNameOp = OptionBuilder.withArgName( "nodeName=value" ) > .hasArgs(2) > .withValueSeparator() > .withDescription( "the server name" ) > .create( "D" ); > > Option nodeIpOp = OptionBuilder.withArgName( "nodeIp=value" ) > .hasArgs(2) > .withValueSeparator() > .withDescription( "server ip" ) > .create( "D" ); > > Option nodePortOp = OptionBuilder.withArgName( "nodePort=value" ) > .hasArgs(2) > .withValueSeparator() > .withDescription( "server port" ) > .create( "D" ); > > Options cmdOptions = new Options(); > cmdOptions.addOption(helpOp); > cmdOptions.addOption(nodeNameOp); > cmdOptions.addOption(nodeIpOp); > cmdOptions.addOption(nodePortOp); > > > HelpFormatter helpFormatter = new HelpFormatter(); > helpFormatter.printHelp("command line help", cmdOptions); > > and here is the output: > usage: command line help > -D <nodePort=value> server port > -h command line help > > Why the help displays only "NodePort"? > > Could anybody give me an example code to use CLI for Java properties? > > Thanks > > Joey Lv > > 12/24/2011 > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org