diff --git a/spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandHelpRenderer.java b/spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandHelpRenderer.java index 641eecd99..1fef73a06 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandHelpRenderer.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/core/command/CommandHelpRenderer.java @@ -82,7 +82,7 @@ private static void appendSynopsis(Command command, StringBuilder helpMessageBui if (!options.isEmpty()) { for (CommandOption option : options) { helpMessageBuilder.append(" "); - if (isRequired(option)) { + if (!isRequired(option)) { helpMessageBuilder.append("["); } if (option.longName() != null) { @@ -92,7 +92,7 @@ private static void appendSynopsis(Command command, StringBuilder helpMessageBui helpMessageBuilder.append("-").append(option.shortName()); } helpMessageBuilder.append(" ").append(option.type().getSimpleName()); - if (isRequired(option)) { + if (!isRequired(option)) { helpMessageBuilder.append("]"); } } diff --git a/spring-shell-core/src/test/java/org/springframework/shell/core/command/CommandHelpRendererTests.java b/spring-shell-core/src/test/java/org/springframework/shell/core/command/CommandHelpRendererTests.java index dc2d252b8..6c2f52adb 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/core/command/CommandHelpRendererTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/core/command/CommandHelpRendererTests.java @@ -127,7 +127,7 @@ void testRenderHelpWithRequiredAndOptionalOptions() { This command says hi to the user. SYNOPSIS - hi [--name String] --times int --help + hi --name String [--times int] --help OPTIONS --name or -n String @@ -173,7 +173,7 @@ void testRenderHelpWithOptionalOptionMissingDefaultValueUsesPrimitiveDefault() { hi - Say hi SYNOPSIS - hi --times int --help + hi [--times int] --help OPTIONS --times or -t int diff --git a/spring-shell-core/src/test/java/org/springframework/shell/core/command/HelpTests.java b/spring-shell-core/src/test/java/org/springframework/shell/core/command/HelpTests.java index 04faad565..9e722e69b 100644 --- a/spring-shell-core/src/test/java/org/springframework/shell/core/command/HelpTests.java +++ b/spring-shell-core/src/test/java/org/springframework/shell/core/command/HelpTests.java @@ -108,7 +108,7 @@ void testHelpMessageForCommand() throws Exception { This command says hi to the user. SYNOPSIS - hi [--name String] --times int --help + hi --name String [--times int] --help OPTIONS --name or -n String @@ -185,7 +185,7 @@ void testHelpMessageForCommandWithArgs() throws Exception { This command says hi to the user. SYNOPSIS - hi --times int [(String)] [(String)] --help + hi [--times int] [(String)] [(String)] --help OPTIONS --times or -t int @@ -259,7 +259,7 @@ void testHelpMessageForCommandWithVariadicArgs() throws Exception { This command says hi to the user. SYNOPSIS - hi --name String (Integer...) --help + hi [--name String] (Integer...) --help OPTIONS --name String @@ -339,7 +339,7 @@ void testSynopsisSpaceBetweenNonRequiredOptions() throws Exception { This command says hi to the user. SYNOPSIS - hi [--name String] --times int --suffix String --help + hi --name String [--times int] [--suffix String] --help OPTIONS --name or -n String @@ -416,7 +416,7 @@ void testHelpMessageForCommandAlias() throws Exception { This command says hi to the user. SYNOPSIS - hi [--name String] --times int --help + hi --name String [--times int] --help OPTIONS --name or -n String @@ -478,7 +478,7 @@ void testHelpMessageForCommandWithoutHelpText() throws Exception { hi - Say hi SYNOPSIS - hi [--name String] --help + hi --name String --help OPTIONS --name or -n String