From 4f7898e173e676817f87039c9f594ef354c8ed70 Mon Sep 17 00:00:00 2001 From: David Pond Date: Sat, 20 May 2023 12:51:24 +0100 Subject: [PATCH] Ensure all subcommands prefixed with commandname This time I've actually fixed the tests. Previously I mistook the deprecation warning for the reason the tests failed. --- src/main/java/picocli/CommandLine.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 37ce9b5a7..81e4df731 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -18659,7 +18659,7 @@ public boolean printSuggestions(PrintWriter writer) { if (!suggestions.isEmpty()) { writer.println(isUnknownOption() ? "Possible solutions: " + str(suggestions) - : "Did you mean: " + this.commandLine.commandSpec.name + " " + str(suggestions).replace(", ", " or ") + "?"); + : "Did you mean: " + str(prefixCommandName(suggestions)).replace(", ", " or ") + "?"); writer.flush(); } return !suggestions.isEmpty(); @@ -18668,6 +18668,18 @@ private static String str(List list) { String s = list.toString(); return s.substring(0, s.length() - 1).substring(1); } + + private List prefixCommandName(List suggestions) + { + String commandName = this.commandLine.commandSpec.name; + if(commandName == null || commandName.trim().isEmpty()) { return suggestions; } + List prefixedSuggestions = new ArrayList(); + for (String s : suggestions) { + prefixedSuggestions.add(commandName + " " + s); + } + return prefixedSuggestions; + } + /** Returns suggested solutions if such solutions exist, otherwise returns an empty list. * @since 3.3.0 */ public List getSuggestions() {