Skip to content

Commit d5ee6f2

Browse files
committed
Consistent formating in examples.
1 parent 1c3b15e commit d5ee6f2

1 file changed

Lines changed: 66 additions & 66 deletions

File tree

src/site/xdoc/usage.xml

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ options.addOption("t", false, "display current time");</source>
7474
<code>DefaultParser</code>.
7575
</p>
7676
<source>CommandLineParser parser = new DefaultParser();
77-
CommandLine cmd = parser.parse( options, args);</source>
77+
CommandLine cmd = parser.parse(options, args);</source>
7878
<p>
7979
Now we need to check if the <code>t</code> option is present. To do
8080
this we will interrogate the
@@ -168,61 +168,61 @@ else {
168168
are the easiest to create. For clarity the constructors for
169169
<code>Option</code> are used here.
170170
</p>
171-
<source>Option help = new Option( "help", "print this message" );
172-
Option projecthelp = new Option( "projecthelp", "print project help information" );
173-
Option version = new Option( "version", "print the version information and exit" );
174-
Option quiet = new Option( "quiet", "be extra quiet" );
175-
Option verbose = new Option( "verbose", "be extra verbose" );
176-
Option debug = new Option( "debug", "print debugging information" );
177-
Option emacs = new Option( "emacs",
178-
"produce logging information without adornments" );</source>
171+
<source>Option help = new Option("help", "print this message");
172+
Option projecthelp = new Option("projecthelp", "print project help information");
173+
Option version = new Option("version", "print the version information and exit");
174+
Option quiet = new Option("quiet", "be extra quiet");
175+
Option verbose = new Option("verbose", "be extra verbose");
176+
Option debug = new Option("debug", "print debugging information");
177+
Option emacs = new Option("emacs",
178+
"produce logging information without adornments");</source>
179179
</subsection>
180180
<subsection name="Argument Options">
181181
<p>
182182
The argument options are created using the <code>Option#Builder</code>.
183183
</p>
184-
<source>Option logfile = Option.builder( "logfile" )
185-
.argName( "file" )
184+
<source>Option logfile = Option.builder("logfile")
185+
.argName("file")
186186
.hasArg()
187-
.desc( "use given file for log" )
187+
.desc("use given file for log")
188188
.build();
189189

190-
Option logger = Option.builder( "logger" )
191-
.argName( "classname" )
190+
Option logger = Option.builder("logger")
191+
.argName("classname")
192192
.hasArg()
193-
.desc( "the class which it to perform logging" )
193+
.desc("the class which it to perform logging")
194194
.build();
195195

196-
Option listener = Option.builder( "listener" )
197-
.argName( "classname" )
196+
Option listener = Option.builder("listener")
197+
.argName("classname")
198198
.hasArg()
199-
.desc( "add an instance of class as "
200-
+ "a project listener" )
199+
.desc("add an instance of class as "
200+
+ "a project listener")
201201
.build();
202202

203-
Option buildfile = Option.builder( "buildfile" )
204-
.argName( "file" )
203+
Option buildfile = Option.builder("buildfile")
204+
.argName("file")
205205
.hasArg()
206-
.desc( "use given buildfile" )
206+
.desc("use given buildfile")
207207
.build();
208208

209-
Option find = Option.builder( "find" )
210-
.argName( "file" )
209+
Option find = Option.builde("find")
210+
.argName("file")
211211
.hasArg()
212-
.desc( "search for buildfile towards the "
213-
+ "root of the filesystem and use it" )
212+
.desc("search for buildfile towards the "
213+
+ "root of the filesystem and use it")
214214
.build();</source>
215215
</subsection>
216216
<subsection name="Java Property Option">
217217
<p>
218218
The last option to create is the Java property and it is also created
219219
using the OptionBuilder.
220220
</p>
221-
<source>Option property = OptionBuilder.withArgName( "property=value" )
221+
<source>Option property = OptionBuilder.withArgName("property=value")
222222
.hasArgs(2)
223223
.withValueSeparator()
224-
.withDescription( "use value for given property" )
225-
.create( "D" );</source>
224+
.withDescription("use value for given property")
225+
.create("D");</source>
226226

227227
The map of properties specified by this option can later be retrieved by
228228
calling <code>getOptionProperties("D")</code> on the <code>CommandLine</code>.
@@ -240,19 +240,19 @@ Option find = Option.builder( "find" )
240240
</p>
241241
<source>Options options = new Options();
242242

243-
options.addOption( help );
244-
options.addOption( projecthelp );
245-
options.addOption( version );
246-
options.addOption( quiet );
247-
options.addOption( verbose );
248-
options.addOption( debug );
249-
options.addOption( emacs );
250-
options.addOption( logfile );
251-
options.addOption( logger );
252-
options.addOption( listener );
253-
options.addOption( buildfile );
254-
options.addOption( find );
255-
options.addOption( property );</source>
243+
options.addOption(help);
244+
options.addOption(projecthelp);
245+
options.addOption(version);
246+
options.addOption(quiet);
247+
options.addOption(verbose);
248+
options.addOption(debug);
249+
options.addOption(emacs);
250+
options.addOption(logfile);
251+
options.addOption(logger);
252+
options.addOption(listener);
253+
options.addOption(buildfile);
254+
options.addOption(find);
255+
options.addOption(property);</source>
256256
<p>
257257
All the preperation is now complete and we are now ready to
258258
parse the command line arguments.
@@ -264,16 +264,16 @@ options.addOption( property );</source>
264264
line arguments, using the rules specified by the <code>Options</code> and
265265
return an instance of <a href="api-release/org/apache/commons/cli/CommandLine.html">CommandLine</a>.
266266
</p>
267-
<source>public static void main( String[] args ) {
267+
<source>public static void main(String[] args) {
268268
// create the parser
269269
CommandLineParser parser = new DefaultParser();
270270
try {
271271
// parse the command line arguments
272-
CommandLine line = parser.parse( options, args );
272+
CommandLine line = parser.parse(options, args);
273273
}
274-
catch( ParseException exp ) {
274+
catch (ParseException exp) {
275275
// oops, something went wrong
276-
System.err.println( "Parsing failed. Reason: " + exp.getMessage() );
276+
System.err.println("Parsing failed. Reason: " + exp.getMessage());
277277
}
278278
}</source>
279279
</subsection>
@@ -284,9 +284,9 @@ options.addOption( property );</source>
284284
the <code>getOptionValue</code> method.
285285
</p>
286286
<source>// has the buildfile argument been passed?
287-
if( line.hasOption( "buildfile" ) ) {
287+
if(line.hasOption("buildfile")) {
288288
// initialise the member variable
289-
this.buildfile = line.getOptionValue( "buildfile" );
289+
this.buildfile = line.getOptionValue("buildfile");
290290
}</source>
291291
</subsection>
292292
<subsection name="Usage/Help">
@@ -298,7 +298,7 @@ if( line.hasOption( "buildfile" ) ) {
298298
</p>
299299
<source>// automatically generate the help statement
300300
HelpFormatter formatter = new HelpFormatter();
301-
formatter.printHelp( "ant", options );</source>
301+
formatter.printHelp("ant", options);</source>
302302
<p>
303303
When executed the following output is produced:
304304
</p>
@@ -318,7 +318,7 @@ formatter.printHelp( "ant", options );</source>
318318
-version print the version information and exit</source>
319319
<p>
320320
If you also require to have a usage statement printed
321-
then calling <code>formatter.printHelp( "ant", options, true )</code>
321+
then calling <code>formatter.printHelp("ant", options, true)</code>
322322
will generate a usage statment as well as the help information.
323323
</p>
324324
</subsection>
@@ -354,37 +354,37 @@ CommandLineParser parser = new DefaultParser();
354354

355355
// create the Options
356356
Options options = new Options();
357-
options.addOption( "a", "all", false, "do not hide entries starting with ." );
358-
options.addOption( "A", "almost-all", false, "do not list implied . and .." );
359-
options.addOption( "b", "escape", false, "print octal escapes for nongraphic "
360-
+ "characters" );
361-
options.addOption( OptionBuilder.withLongOpt( "block-size" )
362-
.withDescription( "use SIZE-byte blocks" )
357+
options.addOption("a", "all", false, "do not hide entries starting with .");
358+
options.addOption("A", "almost-all", false, "do not list implied . and ..");
359+
options.addOption("b", "escape", false, "print octal escapes for nongraphic "
360+
+ "characters");
361+
options.addOption(OptionBuilder.withLongOpt("block-size")
362+
.withDescription("use SIZE-byte blocks")
363363
.hasArg()
364364
.withArgName("SIZE")
365-
.create() );
366-
options.addOption( "B", "ignore-backups", false, "do not list implied entried "
365+
.create());
366+
options.addOption("B", "ignore-backups", false, "do not list implied entried "
367367
+ "ending with ~");
368-
options.addOption( "c", false, "with -lt: sort by, and show, ctime (time of last "
368+
options.addOption("c", false, "with -lt: sort by, and show, ctime (time of last "
369369
+ "modification of file status information) with "
370370
+ "-l:show ctime and sort by name otherwise: sort "
371-
+ "by ctime" );
372-
options.addOption( "C", false, "list entries by columns" );
371+
+ "by ctime");
372+
options.addOption("C", false, "list entries by columns");
373373

374374
String[] args = new String[]{ "--block-size=10" };
375375

376376
try {
377377
// parse the command line arguments
378-
CommandLine line = parser.parse( options, args );
378+
CommandLine line = parser.parse(options, args);
379379

380380
// validate that block-size has been set
381-
if( line.hasOption( "block-size" ) ) {
381+
if (line.hasOption("block-size")) {
382382
// print the value of block-size
383-
System.out.println( line.getOptionValue( "block-size" ) );
383+
System.out.println(line.getOptionValue("block-size"));
384384
}
385385
}
386-
catch( ParseException exp ) {
387-
System.out.println( "Unexpected exception:" + exp.getMessage() );
386+
catch (ParseException exp) {
387+
System.out.println("Unexpected exception:" + exp.getMessage());
388388
}</source>
389389
</section>
390390
</body>

0 commit comments

Comments
 (0)