commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From LvXiaoyi <mrl...@hotmail.com>
Subject [cli] - how to use CLI for Java like properties
Date Sat, 24 Dec 2011 05:43:53 GMT




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



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