java - how to use property=value in CLI commons Library -
i trying use optionbuilder.withargname( "property=value" )
if option called status , command line was:
--status p=11 s=22
it succeeds identify first argument 11 , fails identify second argument...
option status = optionbuilder.withlongopt("status") .withargname( "property=value" ) .hasargs(2) .withvalueseparator() .withdescription("get status") .create('s'); options.addoption(status);
thanks in advance
you can access passed properties using simple modification of passed command line options
--status p=11 --status s=22
or short syntax
-s p=11 -s s=22
in case can access properties code
if (cmd.hasoption("status")) { properties props = cmd.getoptionproperties("status"); system.out.println(props.getproperty("p")); system.out.println(props.getproperty("t")); }
if need use syntax strictly, can manually parse property=value pairs. in case should remove .withvalueseparator() call, , use
string [] propvalues = cmd.getoptionvalues("status"); (string propvalue : propvalues) { string [] values = propvalue.split("="); system.out.println(values[0] + " : " + values[1]); }
Comments
Post a Comment