2121
2222 <properties >
2323 <author email =" dev@commons.apache.org" >commons-dev</author >
24- <title >Usage Scenarios </title >
24+ <title >Using Apache Commons CLI </title >
2525 </properties >
2626
2727 <body >
28- <section name =" Usage Scenarios " >
28+ <section name =" Using Apache Commons CLI " >
2929 <p >
3030 The following sections describe some example scenarios on how to
3131 use CLI in applications.
4343 also printed.
4444 </p >
4545 </subsection >
46- <subsection name =" Create the Options" >
46+ <subsection name =" Creating the Options" >
4747 <p >
4848 An <a href =" api-release/org/apache/commons/cli/Options.html" >
4949 Options</a > object must be created and the <code >Option</code > must be
9292}</source >
9393 <p >
9494 <h4 >Note.</h4 >
95- As of version 1.5-SNAPSHOT (as of 7/31/2017) , the
95+ As of version 1.5, the
9696 <code >DefaultParser</code >'s constructor now has an override with
9797 the signature <code >DefaultParser(final boolean allowPartialMatching)</code >.
9898 Given the following code:
@@ -139,9 +139,8 @@ else {
139139 </subsection >
140140 </section >
141141
142- <section name =" Ant Example" >
142+ <section name =" Using Ant as an Example" >
143143 <p >
144- One of the most ubiquitous Java applications
145144 <a href =" http://ant.apache.org/" >Ant</a > will be used
146145 here to illustrate how to create the <code >Options</code > required. The following
147146 is the help output for Ant.
@@ -162,7 +161,7 @@ else {
162161 -D< property>=< value> use value for given property
163162 -find < file> search for buildfile towards the root of the
164163 filesystem and use it</source >
165- <subsection name =" Boolean Options" >
164+ <subsection name =" Defining Boolean Options" >
166165 <p >
167166 Lets create the boolean options for the application as they
168167 are the easiest to create. For clarity the constructors for
@@ -177,7 +176,7 @@ Option debug = new Option("debug", "print debugging information");
177176Option emacs = new Option("emacs",
178177 "produce logging information without adornments");</source >
179178 </subsection >
180- <subsection name =" Argument Options" >
179+ <subsection name =" Defining Argument Options" >
181180 <p >
182181 The argument options are created using the <code >Option#Builder</code >.
183182 </p >
@@ -213,22 +212,21 @@ Option find = Option.builde("find")
213212 + "root of the filesystem and use it")
214213 .build();</source >
215214 </subsection >
216- <subsection name =" Java Property Option" >
215+ <subsection name =" Defining Java Property Option" >
217216 <p >
218217 The last option to create is the Java property and it is also created
219218 using the OptionBuilder.
220219 </p >
221- <source >Option property = OptionBuilder.withArgName("property=value")
222- .hasArgs(2)
223- .withValueSeparator()
224- .withDescription("use value for given property")
225- .create("D");</source >
220+ <source >Option property = Option property = Option.builder("D")
221+ .hasArgs()
222+ .valueSeparator('=')
223+ .build();</source >
226224
227225 The map of properties specified by this option can later be retrieved by
228226 calling <code >getOptionProperties("D")</code > on the <code >CommandLine</code >.
229227
230228 </subsection >
231- <subsection name =" Create the Options" >
229+ <subsection name =" Creating the Options" >
232230 <p >
233231 Now that we have created each
234232 <a href =" api-release/org/apache/commons/cli/Option.html" >Option</a > we need
@@ -258,7 +256,7 @@ options.addOption(property);</source>
258256 parse the command line arguments.
259257 </p >
260258 </subsection >
261- <subsection name =" Create the Parser" >
259+ <subsection name =" Creating the Parser" >
262260 <p >
263261 We now need to create a <code >CommandLineParser</code >. This will parse the command
264262 line arguments, using the rules specified by the <code >Options</code > and
@@ -289,7 +287,7 @@ if(line.hasOption("buildfile")) {
289287 this.buildfile = line.getOptionValue("buildfile");
290288}</source >
291289 </subsection >
292- <subsection name =" Usage/ Help" >
290+ <subsection name =" Displaying Usage and Help" >
293291 <p >
294292 CLI also provides the means to automatically generate usage
295293 and help information. This is achieved with the
@@ -324,7 +322,7 @@ formatter.printHelp("ant", options);</source>
324322 </subsection >
325323 </section >
326324
327- <section name =" ls Example" >
325+ <section name =" Creating an ls Example" >
328326 <p >
329327 One of the most widely used command line applications in the *nix world
330328 is <code >ls</code >. Due to the large number of options required for <code >ls</code >
@@ -337,7 +335,7 @@ Sort entries alphabetically if none of -cftuSUX nor --sort.
337335
338336-a, --all do not hide entries starting with .
339337-A, --almost-all do not list implied . and ..
340- -b, --escape print octal escapes for nongraphic characters
338+ -b, --escape print octal escapes for non-graphic characters
341339 --block-size=SIZE use SIZE-byte blocks
342340-B, --ignore-backups do not list implied entries ending with ~
343341-c with -lt: sort by, and show, ctime (time of last
@@ -356,14 +354,13 @@ CommandLineParser parser = new DefaultParser();
356354Options options = new Options();
357355options.addOption("a", "all", false, "do not hide entries starting with .");
358356options.addOption("A", "almost-all", false, "do not list implied . and ..");
359- options.addOption("b", "escape", false, "print octal escapes for nongraphic "
357+ options.addOption("b", "escape", false, "print octal escapes for non-graphic "
360358 + "characters");
361- options.addOption(OptionBuilder.withLongOpt ("block-size")
362- .withDescription ("use SIZE-byte blocks")
359+ options.addOption(Option.builder("SIZE").longOpt ("block-size")
360+ .desc ("use SIZE-byte blocks")
363361 .hasArg()
364- .withArgName("SIZE")
365- .create());
366- options.addOption("B", "ignore-backups", false, "do not list implied entried "
362+ .build());
363+ options.addOption("B", "ignore-backups", false, "do not list implied entries "
367364 + "ending with ~");
368365options.addOption("c", false, "with -lt: sort by, and show, ctime (time of last "
369366 + "modification of file status information) with "
0 commit comments