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

fix #1366 point 1 (the help command arity) #1370

Merged
merged 3 commits into from
Dec 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "commands" },
{ "name" : "command" },
{ "name" : "helpRequested" }
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "commands" },
{ "name" : "command" },
{ "name" : "helpRequested" }
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "commands" },
{ "name" : "command" },
{ "name" : "helpRequested" }
]
},
Expand Down
2 changes: 1 addition & 1 deletion picocli-codegen/src/test/resources/example-reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"fields" : [
{ "name" : "commands" },
{ "name" : "command" },
{ "name" : "helpRequested" }
]
},
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -14751,9 +14751,9 @@ public static final class HelpCommand implements IHelpCommandInitializable, IHel
description = "Show usage help for the help command and exit.")
private boolean helpRequested;

@Parameters(paramLabel = "COMMAND", descriptionKey = "helpCommand.command",
@Parameters(paramLabel = "COMMAND", arity="0..1", descriptionKey = "helpCommand.command",
description = "The COMMAND to display the usage help message for.")
private String[] commands = new String[0];
private String command;
remkop marked this conversation as resolved.
Show resolved Hide resolved

private CommandLine self;
private PrintStream out;
Expand All @@ -14768,9 +14768,9 @@ public void run() {
CommandLine parent = self == null ? null : self.getParent();
if (parent == null) { return; }
Help.ColorScheme colors = colorScheme != null ? colorScheme : Help.defaultColorScheme(ansi);
if (commands.length > 0) {
if (command != null) {
Map<String, CommandLine> parentSubcommands = parent.getCommandSpec().subcommands();
String fullName = commands[0];
String fullName = command;
if (parent.isAbbreviatedSubcommandsAllowed()) {
fullName = AbbreviationMatcher.match(parentSubcommands.keySet(), fullName,
parent.isSubcommandsCaseInsensitive(), self);
Expand All @@ -14783,7 +14783,7 @@ public void run() {
subcommand.usage(out, colors); // for compatibility with pre-4.0 clients
}
} else {
throw new ParameterException(parent, "Unknown subcommand '" + commands[0] + "'.", null, commands[0]);
throw new ParameterException(parent, "Unknown subcommand '" + command + "'.", null, command);
}
} else {
if (outWriter != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/picocli/HelpSubCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ class App implements Runnable{ public void run(){}}
String expected = String.format("" +
"Displays help information about the specified command%n" +
"%n" +
"Usage: <main class> help [-h] [COMMAND...]%n" +
"Usage: <main class> help [-h] [COMMAND]%n" +
"%n" +
"When no COMMAND is given, the usage help for the main command is displayed.%n" +
"If a COMMAND is specified, the help for that command is shown.%n" +
"%n" +
" [COMMAND...] The COMMAND to display the usage help message for.%n" +
" -h, --help Show usage help for the help command and exit.%n");
" [COMMAND] The COMMAND to display the usage help message for.%n" +
" -h, --help Show usage help for the help command and exit.%n");
assertEquals(expected, sw.toString());

sw = new StringWriter();
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/picocli/I18nTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,14 @@ public void testLocalizeBuiltInHelp_Shared() {
"Shared header heading%n" +
"i18n-sub HELP command header%n" +
"%n" +
"Usage: i18n-top i18n-sub help [-h] [COMMAND...]%n" +
"Usage: i18n-top i18n-sub help [-h] [COMMAND]%n" +
"Shared description 0%n" +
"Shared description 1%n" +
"Shared description 2%n" +
" [COMMAND...] Shared description of COMMAND parameter of built-in help%n" +
" subcommand%n" +
" -h, --help Shared description of --help option of built-in help%n" +
" subcommand%n" +
" [COMMAND] Shared description of COMMAND parameter of built-in help%n" +
" subcommand%n" +
" -h, --help Shared description of --help option of built-in help%n" +
" subcommand%n" +
"Shared Exit Codes Heading%n" +
"These exit codes are blah blah etc.%n" +
" 00 (From shared bundle) Normal termination%n" +
Expand Down Expand Up @@ -625,14 +625,14 @@ public void testLocalizeBuiltInHelp_Specialized() {
"Shared header heading%n" +
"i18n-top HELP command header%n" +
"%n" +
"Usage: i18n-top help [-h] [COMMAND...]%n" +
"Usage: i18n-top help [-h] [COMMAND]%n" +
"Shared description 0%n" +
"Shared description 1%n" +
"Shared description 2%n" +
" [COMMAND...] Specialized description of COMMAND parameter of i18-top%n" +
" help subcommand%n" +
" -h, --help Specialized description of --help option of i18-top help%n" +
" subcommand%n" +
" [COMMAND] Specialized description of COMMAND parameter of i18-top help%n" +
" subcommand%n" +
" -h, --help Specialized description of --help option of i18-top help%n" +
" subcommand%n" +
"Shared Exit Codes Heading%n" +
"These exit codes are blah blah etc.%n" +
" 00 (From shared bundle) Normal termination%n" +
Expand Down