Skip to content

Commit

Permalink
[#1071] Usage help no longer renders options header when it is specif…
Browse files Browse the repository at this point in the history
…ied via `optionListHeading` when all options are hidden.

Closes #1071
  • Loading branch information
remkop committed Jun 4, 2020
1 parent b712a97 commit 37d1788
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ When abbreviated options are enabled, user input `-AB` will match the long `-Aaa
* [#1070] Enhancement: Code cleanup: removed redundant modifiers and initializations, unused variables, incorrect javadoc references, and more. Thanks to [NewbieOrange](https://github.com/NewbieOrange) for the pull request.
* [#1096] Enhancement: Override `Help.Column` `equals`, `hashCode` and `toString` methods to facilitate testing.
* [#1063][#1064] `ManPageGenerator` now correctly excludes hidden options, parameters, and subcommands from man page generation. Thanks to [Brian Demers](https://github.com/bdemers) for the pull request.
* [#1071] Bugfix: Usage help no longer renders options header when it is specified via `optionListHeading` when all options are hidden.
* [#1081] Bugfix: `CommandLine.Help` constructor no longer calls overridable methods `addAllSubcommands` and `createDefaultParamLabelRenderer`.
* [#1065] Bugfix: With a `List<>` option in `@ArgGroup`, group incorrectly appears twice in the synopsis. Thanks to [kap4lin](https://github.com/kap4lin) for raising this.
* [#1067] Bugfix: `ParserSpec::initFrom` was not copying `useSimplifiedAtFiles`.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -14769,7 +14769,9 @@ public String parameterListHeading(Object... params) {
* @param params the parameters to use to format the option list heading
* @return the formatted option list heading */
public String optionListHeading(Object... params) {
if (commandSpec.usageMessage().showEndOfOptionsDelimiterInUsageHelp() || !commandSpec.optionsMap().isEmpty()) {
boolean hasVisibleOption = false;
for (OptionSpec option : commandSpec.options()) { hasVisibleOption |= !option.hidden(); }
if (commandSpec.usageMessage().showEndOfOptionsDelimiterInUsageHelp() || hasVisibleOption) {
return createHeading(commandSpec.usageMessage().optionListHeading(), params);
}
return "";
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/picocli/HelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4881,4 +4881,20 @@ class App {
" HIDDEN hidden positional%n" +
" VISIBLE visible positional%n"), layout.toString());
}

@Test
public void test1071OptionListHeadingWithOneHiddenOption() {
@Command(optionListHeading = "%nOptions:%n",
subcommands = {HelpCommand.class})
class MyTool {
@Option(names = { "--hidden" }, hidden = true)
String hidden = null;
}
String expected = String.format("" +
"Usage: <main class> [COMMAND]%n" +
"Commands:%n" +
" help Displays help information about the specified command%n");
String actual = new CommandLine(new MyTool()).getUsageMessage();
assertEquals(expected, actual);
}
}

0 comments on commit 37d1788

Please sign in to comment.