From 2e7ce24b084e76c425575baf6a67cff338d79021 Mon Sep 17 00:00:00 2001 From: Remko Popma Date: Sat, 31 Aug 2024 20:58:06 +0900 Subject: [PATCH] [#2331] Bugfix: AutoComplete with jline3 was showing hidden commands Closes #2331 --- RELEASE-NOTES.md | 3 ++- .../src/main/java/picocli/shell/jline3/PicocliCommands.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index d51119af3..26b7a4b01 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -24,7 +24,8 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96). ## Fixed issues -* [#2335] Module info missing in all jars except the main picocli jar file. Thanks to [Oliver B. Fischer](https://github.com/obfischer) for raising this. +* [#2335] Bugfix: Module info missing in all jars except the main picocli jar file. Thanks to [Oliver B. Fischer](https://github.com/obfischer) for raising this. +* [#2331] Bugfix: AutoComplete with jline3 was showing hidden commands. Thanks to [clebertsuconic](https://github.com/clebertsuconic) for raising this. * [#2290] DOC: User guide, CDI 2.0 (JSR 365) section: fix example and add warning about dynamic proxies. Thanks to [Mert Zeybekler](https://github.com/Mert-Z) for the pull request. diff --git a/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java b/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java index b4a8bbde3..723c3f0e1 100644 --- a/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java +++ b/picocli-shell-jline3/src/main/java/picocli/shell/jline3/PicocliCommands.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -170,7 +171,7 @@ public void complete(LineReader reader, ParsedLine commandLine, List String word = commandLine.word(); List words = commandLine.words(); CommandLine sub = findSubcommandLine(words, commandLine.wordIndex()); - if (sub == null) { + if (sub == null || sub.getCommandSpec().usageMessage().hidden()) { return; } if (word.startsWith("-")) { @@ -192,9 +193,9 @@ public void complete(LineReader reader, ParsedLine commandLine, List } } } else { - addCandidates(candidates, sub.getSubcommands().keySet()); for (CommandLine s : sub.getSubcommands().values()) { if (!s.getCommandSpec().usageMessage().hidden()) { + addCandidates(candidates, Collections.singletonList(s.getCommandSpec().name())); addCandidates(candidates, Arrays.asList(s.getCommandSpec().aliases())); } }