Skip to content

Commit

Permalink
fix #1366 point 1 (the help command arity)
Browse files Browse the repository at this point in the history
  • Loading branch information
peutch authored and remkop committed Dec 1, 2021
1 parent a98df85 commit 3b53e00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -14789,9 +14789,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;

private CommandLine self;
private PrintStream out;
Expand All @@ -14806,9 +14806,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 @@ -14821,7 +14821,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

0 comments on commit 3b53e00

Please sign in to comment.