Skip to content

Commit

Permalink
Merge pull request cbeust#512 from mkarg/hide-command-section
Browse files Browse the repository at this point in the history
usage() hides 'Comments:' header when ONLY hidden commands exist
  • Loading branch information
cbeust authored Mar 23, 2021
2 parents d473f2c + b7b0d1d commit 947cd54
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/beust/jcommander/DefaultUsageFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin
* @param indent the indentation
*/
public void appendCommands(StringBuilder out, int indentCount, int descriptionIndent, String indent) {
boolean hasOnlyHiddenCommands = true;
for (Map.Entry<JCommander.ProgramName, JCommander> commands : commander.getRawCommands().entrySet()) {
Object arg = commands.getValue().getObjects().get(0);
Parameters p = arg.getClass().getAnnotation(Parameters.class);

if (p == null || !p.hidden())
hasOnlyHiddenCommands = false;
}

if (hasOnlyHiddenCommands)
return;

out.append(indent + " Commands:\n");

// The magic value 3 is the number of spaces between the name of the option and its description
Expand Down

0 comments on commit 947cd54

Please sign in to comment.