apache-commons-cli

how to use property=value in CLI commons Library

怎甘沉沦 提交于 2019-12-13 13:21:23
问题 I am trying to use the OptionBuilder.withArgName( "property=value" ) If my Option is called status and my command line was: --status p=11 s=22 It only succeeds to identify the first argument which is 11 and it fails to identify the second argument... Option status = OptionBuilder.withLongOpt("status") .withArgName( "property=value" ) .hasArgs(2) .withValueSeparator() .withDescription("Get the status") .create('s'); options.addOption(status); Thanks for help in advance 回答1: You can access to

Apache command line parser

廉价感情. 提交于 2019-12-11 10:47:36
问题 I got the code below from a sample code from tutorials point and tweaked it a little bit. App.java public static void main(String[] args) throws ParseException { CommandTest t = new CommandTest(); t.start(args); } CommandTest.java public class CommandTest { void start(String[] args) throws ParseException { //***Definition Stage*** // create Options object Options options = new Options(); // add option "-a" options.addOption( Option.builder("a") .longOpt("add") .desc("add numbers") .hasArg

Repeated option groups with Commons CLI?

本秂侑毒 提交于 2019-12-11 03:17:31
问题 I have a specific set of requirements for parsing command line options. My intent is not unlike the Linux beep command, in which you can specify multiple beeps of different frequencies and durations. I just happen to be working with 4-bit colors. Example of a valid input series: -z 1 -r 5 -g 2 -b 12 -z 4 --color=ffe --zone=3 --color=8,8,4 The -z or --zone is the separator that starts a new option group. Colors may be specified with -r/g/b settings, or --color. I expect to handle parsing that

Defining positional parameters with apache commons cli

早过忘川 提交于 2019-12-10 12:47:34
问题 I would like to define an Apache Commons CLI parser that includes named arguments and positional arguments. program [-a optA] [-b optB] [-f] pos1 pos2 How do I validate pos1 and pos2? 回答1: One a quick read of the documentation, I was not aware the the CommandLine class would provide access to the remaining positional parameters. After parsing the Options passed on the command line, the remaining arguments are available in the CommandLine.getArgs() method. public static void main(String[] args

Apache Commons CLI: replacement for deprecated OptionBuilder?

…衆ロ難τιáo~ 提交于 2019-12-10 12:30:53
问题 IntelliJ shows that OptionBuilder is deprecated in this example code from http://commons.apache.org/proper/commons-cli/usage.html. What should I use as the replacement? import org.apache.commons.cli.*; Options options = new Options(); options.addOption(OptionBuilder.withLongOpt( "block-size" ) .withDescription( "use SIZE-byte blocks" ) .hasArg() .withArgName("SIZE") .create()); 回答1: From http://commons.apache.org/proper/commons-cli/javadocs/api-release/index.html Deprecated. since 1.3, use

How to specify multiple options using apache commons cli?

旧时模样 提交于 2019-12-06 01:41:39
问题 I want something like: java programName -jobs1 -C 10 -W 20 java programName -job2 java programName -job3 With contents: Option o1 = new Option("job2", "some desc"); Option o2 = new Option("job3" , "(some desc") Option o3 = OptionBuilder.hasArgs(2).withArgName( "W" ).withArgName("C").withDescription( "Some desc" ).create("job1") Option o4 = new Option("help"); Options os = new Options().addOption(o1).addOption(o2).addOption(o3).addOption(o4). HelpFormatter formatter = new HelpFormatter();

command line parsing using apache commons cli

拥有回忆 提交于 2019-12-05 19:39:00
M tryng to use apache commons cli , My use case is variable number of arguments with some options. Say -p str1 str2; It can be -p str1 str2 str3 .. strn Another is -m str1 -h with cmdline.getOptionValues("p"); It fetches only last string.How can I fetch all the values of an particular option? Edit: if(cmdline.hasOption("p")){ String[] argsList = cmdline.getOptionValues(p); String strLine = Arrays.toString(argsList); argsList = strLine.split(","); } M i doing it right? will string consist of exactly data I want or smthng unexpected white spaces r anythng else? Use hasArgs() with a value

Get name of executable jar from within main() method [duplicate]

≡放荡痞女 提交于 2019-12-03 04:48:14
问题 This question already has answers here : How to get the path of a running JAR file? (29 answers) Closed 4 years ago . I've created an executable jar and using commons-cli to give the user the ability to specify command line parameters when he launches the client. Everything works fine. However, when I print the usage statement for the jar, I would like to show the following: usage: java -jar myprog.jar <options> <file> --help Display the help message --debug Enable debugging .... Printing of

Get name of executable jar from within main() method [duplicate]

*爱你&永不变心* 提交于 2019-12-02 18:00:00
This question already has an answer here: How to get the path of a running JAR file? 28 answers I've created an executable jar and using commons-cli to give the user the ability to specify command line parameters when he launches the client. Everything works fine. However, when I print the usage statement for the jar, I would like to show the following: usage: java -jar myprog.jar <options> <file> --help Display the help message --debug Enable debugging .... Printing of all the options is easily done with commons-cli. However, the "usage" line is the head scratcher. I cannot seem to figure out

Scala error compiling OptionBuilder

大兔子大兔子 提交于 2019-12-01 17:48:21
问题 I am using Apache commons cli (1.2) for command line parsing. I have the following in my code: import org.apache.commons.cli.OptionBuilder OptionBuilder.withLongOpt("db-host").hasArg. withDescription("Name of the database host").create('h') I get the error hasArg is not a member of org.apache.commons.cli.OptionBuilder . It makes no difference if I change .hasArg to .hasArg() . Why? BTW, Java parses this fine. 回答1: import org.apache.commons.cli.OptionBuilder OptionBuilder.withLongOpt("db-host"