Skip to content

Commit 2fcffe4

Browse files
committed
Changes as per review
1 parent 11c63fc commit 2fcffe4

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/main/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,14 @@ public Builder setShowDeprecated(final boolean useDefaultFormat) {
130130
}
131131

132132
/**
133-
* Returns the option description or an empty string if the description is {@code null}.
133+
* Gets the option description or an empty string if the description is {@code null}.
134134
* @param option The option to get the description from.
135135
* @return the option description or an empty string if the description is {@code null}.
136+
* @since 2.17.0
136137
*/
137138
public static String getDescription(final Option option) {
138-
return option.getDescription() == null ? "" : option.getDescription();
139+
String desc = option.getDescription();
140+
return desc == null ? "" : desc;
139141
}
140142
/**
141143
* This class implements the {@code Comparator} interface for comparing Options.
@@ -274,7 +276,7 @@ private static PrintWriter createDefaultPrintWriter() {
274276
protected Comparator<Option> optionComparator = new OptionComparator();
275277

276278
/**
277-
* BiFunction to format the description for a deprecated option.
279+
* Function to format the description for a deprecated option.
278280
*/
279281
private final Function<Option, String> deprecatedFormatFunc;
280282

src/site/xdoc/usage.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,14 @@ public static void main(String[] args) {
404404
try {
405405
// parse the command line arguments
406406
CommandLine line = parser.parse(options, args);
407-
}
408-
catch (ParseException exp) {
407+
} catch (ParseException exp) {
409408
// oops, something went wrong
410409
System.err.println("Parsing failed. Reason: " + exp.getMessage());
411410
}
412411

413412
try {
414413
Integer value = line.getParsedOptionValue(count);
415-
System.out.format("The value is %s\m", value );
414+
System.out.format("The value is %s%n", value );
416415
} catch (ParseException e) {
417416
e.printStackTrace();
418417
}
@@ -449,7 +448,7 @@ public static void main(String[] args) {
449448
Option fooOpt = Option.builder("foo")
450449
.hasArg()
451450
.desc("the foo arg")
452-
.converter((s) -> new Foo(s))
451+
.converter(Foo::new)
453452
.build();</source>
454453
The above will create an option that passes the string value to the Foo constructor when <code>commandLine.getParsedOptionValue(fooOpt)</code> is called.
455454
</p>
@@ -509,10 +508,10 @@ public static void main(String[] args) {
509508
try {
510509
// parse the command line arguments
511510
line = parser.parse(options, new String[] {"-n", "5"});
512-
System.out.println( "n="+line.getParsedOptionValue("n"));
511+
System.out.println("n=" + line.getParsedOptionValue("n"));
513512
} catch (ParseException exp) {
514513
// oops, something went wrong
515-
System.err.println("Parsing failed. Reason: " + exp.getMessage());
514+
System.err.println("Parsing failed. Reason: " + exp.getMessage());
516515
}
517516
} </source>
518517
<p>
@@ -544,10 +543,10 @@ public static void main(String[] args) {
544543
try {
545544
// parse the command line arguments
546545
line = parser.parse(options, new String[] {"-n", "5"});
547-
System.out.println( "n="+line.getParsedOptionValue("n"));
546+
System.out.println("n=" + line.getParsedOptionValue("n"));
548547
} catch (ParseException exp) {
549548
// oops, something went wrong
550-
System.err.println("Parsing failed. Reason: " + exp.getMessage());
549+
System.err.println("Parsing failed. Reason: " + exp.getMessage());
551550
}
552551
} </source>
553552
<p>
@@ -589,7 +588,7 @@ public static void main(String[] args) {
589588
As an example of the second case above, changing the implementation of <code>doSomething</code> to
590589
<source>
591590
void doSomething(Options options) {
592-
Function&lt;Option, String> disp = option -> String.format( "%s. %s", HelpFormatter.getDescription(option),
591+
Function&lt;Option, String> disp = option -> String.format("%s. %s", HelpFormatter.getDescription(option),
593592
option.getDeprecated().toString());
594593
HelpFormatter formatter = HelpFormatter.builder().setShowDeprecated(disp).get();
595594
formatter.printHelp("Command line syntax:", options);

0 commit comments

Comments
 (0)