Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcommand suggestions #2027

Merged
merged 3 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -18487,7 +18487,7 @@ public static class TypeConversionException extends PicocliException {
/** Exception indicating something went wrong while parsing command line options. */
public static class ParameterException extends PicocliException {
private static final long serialVersionUID = 1477112829129763139L;
private final CommandLine commandLine;
protected final CommandLine commandLine;
private ArgSpec argSpec = null;
private String value = null;

Expand Down Expand Up @@ -18659,7 +18659,7 @@ public boolean printSuggestions(PrintWriter writer) {
if (!suggestions.isEmpty()) {
writer.println(isUnknownOption()
? "Possible solutions: " + str(suggestions)
: "Did you mean: " + str(suggestions).replace(", ", " or ") + "?");
: "Did you mean: " + this.commandLine.commandSpec.name + " " + str(suggestions).replace(", ", " or ") + "?");
writer.flush();
}
return !suggestions.isEmpty();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/picocli/UnmatchedArgumentExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testUnmatchedArgumentSuggestsSubcommands() {
Demo.mainCommand().parseWithHandler(((CommandLine.IParseResultHandler)null), new PrintStream(baos), new String[]{"chekcout"});
String expected = format("" +
"Unmatched argument at index 0: 'chekcout'%n" +
"Did you mean: checkout or help or branch?%n");
"Did you mean: git checkout or git help or git branch?%n");
assertEquals(expected, baos.toString());
}
@Test
Expand All @@ -90,7 +90,7 @@ public void testUnmatchedArgumentSuggestsSubcommands2() {
Demo.mainCommand().parseWithHandler(((CommandLine.IParseResultHandler)null), new PrintStream(baos), new String[]{"me"});
String expected = format("" +
"Unmatched argument at index 0: 'me'%n" +
"Did you mean: merge?%n");
"Did you mean: git merge?%n");
assertEquals(expected, baos.toString());
}

Expand Down