Skip to content

Cleanup help formatting#277

Merged
garydgregory merged 4 commits into
apache:masterfrom
Claudenw:cleanup_help_formatting
May 19, 2024
Merged

Cleanup help formatting#277
garydgregory merged 4 commits into
apache:masterfrom
Claudenw:cleanup_help_formatting

Conversation

@Claudenw

Copy link
Copy Markdown
Contributor

Changes to simplify deprecated help output.

  • Changed deprecatedFormatFunc from BiFunction<String, Option, String> to Function<Option,String>
  • updated docs
  • added HelpFormatter.getDescription(Option) to provide a function does not return null for getDescription

@codecov-commenter

codecov-commenter commented May 18, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.83%. Comparing base (9f6b23b) to head (52d9311).
Report is 199 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #277      +/-   ##
============================================
+ Coverage     91.90%   95.83%   +3.93%     
- Complexity      575      658      +83     
============================================
  Files            22       23       +1     
  Lines          1247     1368     +121     
  Branches        210      225      +15     
============================================
+ Hits           1146     1311     +165     
+ Misses           63       25      -38     
+ Partials         38       32       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Claudenw Claudenw marked this pull request as ready for review May 18, 2024 06:41
@Claudenw Claudenw requested a review from garydgregory May 18, 2024 06:41

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Claudenw
Thank you for your PR. Please see my comments.

* Returns the option description or an empty string if the description is {@code null}.
* @param option The option to get the description from.
* @return the option description or an empty string if the description is {@code null}.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New public and protected elements need Javadoc since tags.
  • In Javadoc, a foo getter methods "Gets foo..." (I've tried to be consistent with this in Commons.)

Comment thread src/site/xdoc/usage.xml Outdated
// parse the command line arguments
CommandLine line = parser.parse(options, args);
}
catch (ParseException exp) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch should be on the same line as the previous }, just like in our code.

* @return the option description or an empty string if the description is {@code null}.
*/
public static String getDescription(final Option option) {
return option.getDescription() == null ? "" : option.getDescription();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only call option.getDescription() once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we don't want to pull in the text utilities here but .... It feels like we do this sort of thing a number of times. In the case that we do implement the same checks multiple times, would it make sense to bring in a striped down StringUtils?

@garydgregory garydgregory May 18, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member

If you want to refactor this, I would only do so with a package private utility method.

Comment thread src/main/java/org/apache/commons/cli/HelpFormatter.java
Comment thread src/site/xdoc/usage.xml Outdated

try {
Integer value = line.getParsedOptionValue(count);
System.out.format("The value is %s\m", value );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\m? Do you mean %n for an EOL?

Comment thread src/site/xdoc/usage.xml Outdated
try {
// parse the command line arguments
line = parser.parse(options, new String[] {"-n", "5"});
System.out.println( "n="+line.getParsedOptionValue("n"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.out.println( "n="+line.getParsedOptionValue("n"));
->
System.out.println("n="+line.getParsedOptionValue("n"));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not: System.out.println("n=" + line.getParsedOptionValue("n")); ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the spacing was off.

Comment thread src/site/xdoc/usage.xml Outdated
System.out.println( "n="+line.getParsedOptionValue("n"));
} catch (ParseException exp) {
// oops, something went wrong
System.err.println("Parsing failed. Reason: " + exp.getMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.err.println("Parsing failed. Reason: " + exp.getMessage());
->
System.err.println("Parsing failed. Reason: " + exp.getMessage());

Comment thread src/site/xdoc/usage.xml Outdated
System.out.println( "n="+line.getParsedOptionValue("n"));
} catch (ParseException exp) {
// oops, something went wrong
System.err.println("Parsing failed. Reason: " + exp.getMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Comment thread src/site/xdoc/usage.xml Outdated
}
</source>
void doSomething(Options options) {
Function&lt;Option, String> disp = option -> String.format( "%s. %s", HelpFormatter.getDescription(option),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String.format( "%s. %s", HelpFormatter.getDescription(option),
->
String.format("%s. %s", HelpFormatter.getDescription(option),

Comment thread src/site/xdoc/usage.xml Outdated
try {
// parse the command line arguments
line = parser.parse(options, new String[] {"-n", "5"});
System.out.println( "n="+line.getParsedOptionValue("n"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Comment thread src/main/java/org/apache/commons/cli/HelpFormatter.java Outdated
@garydgregory garydgregory merged commit 0b115d5 into apache:master May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants