Skip to content

Commit 28e5d29

Browse files
author
Nicola Di Falco
committed
fix: display required only if no default value
1 parent 9529dcc commit 28e5d29

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-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/src/main/java/org/springframework/shell/samples/standard/ComponentCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@
3939
import org.springframework.shell.standard.AbstractShellComponent;
4040
import org.springframework.shell.standard.ShellComponent;
4141
import org.springframework.shell.standard.ShellMethod;
42+
import org.springframework.shell.standard.ShellOption;
4243
import org.springframework.util.StringUtils;
4344

4445
@ShellComponent
4546
public class ComponentCommands extends AbstractShellComponent {
4647

4748
@ShellMethod(key = "component string", value = "String input", group = "Components")
48-
public String stringInput(boolean mask, boolean required) {
49-
StringInput component = new StringInput(getTerminal(), "Enter value", null);
49+
public String stringInput(boolean mask, boolean required, @ShellOption(defaultValue = ShellOption.NULL) String defaultValue) {
50+
StringInput component = new StringInput(getTerminal(), "Enter value", defaultValue);
5051
component.setResourceLoader(getResourceLoader());
5152
component.setTemplateExecutor(getTemplateExecutor());
5253
component.setRequired(required);

0 commit comments

Comments
 (0)