Skip to content

Commit

Permalink
Ensure all subcommands prefixed with commandname
Browse files Browse the repository at this point in the history
This time I've actually fixed the tests. Previously I mistook the deprecation warning for the reason the tests failed.
  • Loading branch information
mauvo committed May 20, 2023
1 parent 77e9941 commit 8a54980
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -18668,6 +18668,18 @@ private static String str(List<String> list) {
String s = list.toString();
return s.substring(0, s.length() - 1).substring(1);
}

private List<String> prefixCommandName(List<String> suggestions)
{
String commandName = this.commandLine.commandSpec.name;
if(commandName == null || commandName.trim().isEmpty()) { return suggestions; }
List<String> prefixedSuggestions = new ArrayList<String>();
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<String> getSuggestions() {
Expand Down

0 comments on commit 8a54980

Please sign in to comment.