Skip to content

Commit

Permalink
Fix usage() for missing description on commands
Browse files Browse the repository at this point in the history
Before this commit, if you supply a command to a JCommander object
and you dont supply a description for the command, then when calling
usage() you will see a line of the following format:
"<command-name> null"

After this commit the string literal "null" will be omitted from the
usage() call if you do not supply a description for the command.

Fixes #480
  • Loading branch information
jkosh44 authored and mkarg committed Oct 4, 2023
1 parent 1fb1e86 commit d5e14a9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ public void appendCommands(StringBuilder out, int indentCount, int descriptionIn
if (p == null || !p.hidden()) {
JCommander.ProgramName progName = commands.getKey();
String dispName = progName.getDisplayName();
String description = indent + s(4) + dispName + s(6) + getCommandDescription(progName.getName());
String commandDescription = Optional.ofNullable(getCommandDescription(progName.getName()))
.map(desc -> s(6) + desc)
.orElse("");
String description = indent + s(4) + dispName + commandDescription;
wrapDescription(out, indentCount + descriptionIndent, description);
out.append("\n");

Expand Down

0 comments on commit d5e14a9

Please sign in to comment.