Skip to content

Commit 6305112

Browse files
committed
fix: display required only if no default value
1 parent fd13219 commit 6305112

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

spring-shell-core/src/main/resources/org/springframework/shell/component/string-input-default.stg

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ info(model) ::= <%
1515
<if(model.maskedInput)>
1616
<model.maskedInput>
1717
<else>
18-
<if(model.required)>
19-
<("[Required]"); format="style-value">
20-
<endif>
2118
<if(model.defaultValue)>
2219
<("[Default "); format="style-value"><model.defaultValue; format="style-value"><("]"); format="style-value">
20+
<elseif(model.required)>
21+
<("[Required]"); format="style-value">
2322
<endif>
2423
<endif>
2524
<else>
2625
<if(model.input)>
2726
<model.input>
2827
<else>
29-
<if(model.required)>
30-
<("[Required]"); format="style-value">
31-
<endif>
3228
<if(model.defaultValue)>
3329
<("[Default "); format="style-value"><model.defaultValue; format="style-value"><("]"); format="style-value">
30+
<elseif(model.required)>
31+
<("[Required]"); format="style-value">
3432
<endif>
3533
<endif>
3634
<endif>

spring-shell-samples/spring-shell-sample-commands/src/main/java/org/springframework/shell/samples/standard/ComponentCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
public class ComponentCommands extends AbstractShellComponent {
5050

5151
@ShellMethod(key = "component string", value = "String input", group = "Components")
52-
public String stringInput(boolean mask, boolean required) {
53-
StringInput component = new StringInput(getTerminal(), "Enter value", null);
52+
public String stringInput(boolean mask, boolean required, @ShellOption(defaultValue = ShellOption.NULL) String defaultValue) {
53+
StringInput component = new StringInput(getTerminal(), "Enter value", defaultValue);
5454
component.setResourceLoader(getResourceLoader());
5555
component.setTemplateExecutor(getTemplateExecutor());
5656
component.setRequired(required);

0 commit comments

Comments
 (0)