Skip to content

Commit

Permalink
[#1076] Bugfix: Don't generate Autocomplete for hidden commands
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jun 30, 2020
1 parent ef78707 commit 59b4299
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ To use the `ManPageGenerator` tool as a subcommand, you will need the `picocli-c
* [#1055] Bugfix: The parser will no longer assign values that match an option name to options that take a parameter, unless the value is in quotes. Thanks to [waacc-gh](https://github.com/waacc-gh) for raising this.
* [#1015] Bugfix: Parser improvement: varargs positional arguments no longer consume unmatched options unless `unmatchedOptionsArePositionalParams` is configured. Thanks to [Chris Smowton](https://github.com/smowton) for raising this.
* [#1071] Bugfix: Usage help no longer renders options header when it is specified via `optionListHeading` when all options are hidden.
* [#1076] Bugfix: Don't generate Autocomplete for hidden commands. Thanks to [power721](https://github.com/power721) for raising this.
* [#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
7 changes: 6 additions & 1 deletion src/main/java/picocli/AutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,12 @@ private static String generateFunctionForCommand(String functionName, String com
List<OptionSpec> argOptionFields = filter(commandSpec.options(), negate(new BooleanArgFilter()));
String argOptionNames = optionNames(argOptionFields);

Set<String> subCommands = commandLine.getSubcommands().keySet();
Set<String> subCommands = new LinkedHashSet<String>();
for (String sub : commandLine.getSubcommands().keySet()) {
if (!commandLine.getSubcommands().get(sub).getCommandSpec().usageMessage().hidden()) {
subCommands.add(sub); // #1076 Don't generate Autocomplete for hidden commands
}
}
// If the command is a HelpCommand, append parent subcommands to the autocompletion list.
if (commandLine.getParent() != null && commandLine.getCommand() instanceof HelpCommand) {
subCommands = new LinkedHashSet<String>(subCommands);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/picocli/AutoCompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ private String getCompletionScriptTextWithHidden(String commandName) {
"function _complete_%1$s() {\n" +
" local cmds0=(help)\n" +
"\n" +
" if CompWordsContainsArray \"${cmds0[@]}\"; then _picocli_CompletionDemo_help; return $?; fi\n" +
" if CompWordsContainsArray \"${cmds0[@]}\"; then _picocli_%1$s_help; return $?; fi\n" +
"\n" +
" # No subcommands were specified; generate completions for the top-level command.\n" +
" _picocli_%1$s; return $?;\n" +
Expand All @@ -1750,9 +1750,9 @@ private String getCompletionScriptTextWithHidden(String commandName) {
" local curr_word=${COMP_WORDS[COMP_CWORD]}\n" +
" local prev_word=${COMP_WORDS[COMP_CWORD-1]}\n" +
"\n" +
" local commands=\"generate-completion help\"\n" +
" local commands=\"help\"\n" + // NOTE: no generate-completion: this command is hidden
" local flag_opts=\"\"\n" +
" local arg_opts=\"--apples --bbb\"\n" +
" local arg_opts=\"--apples --bbb\"\n" + // NOTE: no --aaa: this option is hidden
"\n" +
" compopt +o default\n" +
"\n" +
Expand Down

0 comments on commit 59b4299

Please sign in to comment.