Skip to content

Commit ce584d3

Browse files
committed
feat: adding documentation
Signed-off-by: Nicola Di Falco <[email protected]>
1 parent 61e64bc commit ce584d3

File tree

7 files changed

+128
-6
lines changed

7 files changed

+128
-6
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ info(model) ::= <%
1414
<if(model.input)>
1515
<model.input>
1616
<else>
17-
<if(model.required)>
18-
<("[Required]"); format="style-value">
19-
<endif>
2017
<("[Number Type: "); format="style-value"><model.defaultClass; format="style-value"><("]"); format="style-value">
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
%>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{"version":2,"width":120,"height":9,"timestamp":1691400709,"env":{"TERM":"ms-terminal","SHELL":"powershell.exe"}}
2+
[1.1047019958496094,"o","\u001b[25l\u001b[m\u001b[93m\u001b[jjava\u001b[m \u001b[90m-jar\u001b[m spring-shell-samples/target/spring-shell-samples-2.1.13-SNAPSHOT.jar\u001b[?25h"]
3+
[1.7505860328674316,"o","\r\n"]
4+
[4.510409593582153,"o","\u001b[?2004h\u001b[33mmy-shell:>"]
5+
[4.519921541213989,"o","\u001b[m"]
6+
[5.577335357666016,"o","\u001b[31mc"]
7+
[5.591983318328857,"o","\u001b[m"]
8+
[5.846746921539307,"o","\u001b[31mo"]
9+
[5.857876777648926,"o","\u001b[m"]
10+
[5.96783971786499,"o","\u001b[31mm"]
11+
[5.98032808303833,"o","\u001b[m"]
12+
[6.270904302597046,"o","\u001b[31mp"]
13+
[6.293165922164917,"o","\u001b[m"]
14+
[6.335582733154297,"o","\u001b[31mo"]
15+
[6.355441093444824,"o","\u001b[m"]
16+
[6.671180009841919,"o","\u001b[31mn"]
17+
[6.684344053268433,"o","\u001b[m"]
18+
[6.855102300643921,"o","\u001b[31me"]
19+
[6.872071743011475,"o","\u001b[m"]
20+
[6.998976230621338,"o","\u001b[31mn"]
21+
[7.0131447315216064,"o","\u001b[m"]
22+
[7.159230947494507,"o","\u001b[31mt"]
23+
[7.1707377433776855,"o","\u001b[m"]
24+
[7.230209112167358,"o","\u001b[31m "]
25+
[7.248788356781006,"o","\u001b[m"]
26+
[7.406573534011841,"o","\u001b[31mn"]
27+
[7.420743227005005,"o","\u001b[m"]
28+
[7.679130554199219,"o","\u001b[31mu"]
29+
[7.699283123016357,"o","\u001b[m"]
30+
[8.135498523712158,"o","\u001b[31mm"]
31+
[8.153958559036255,"o","\u001b[m"]
32+
[8.374905347824097,"o","\u001b[31mb"]
33+
[8.38698434829712,"o","\u001b[m"]
34+
[8.527199268341064,"o","\u001b[31me"]
35+
[8.543792724609375,"o","\u001b[m"]
36+
[8.719360589981079,"o","\u001b[25l\u001b[2;11H\u001b[?25h"]
37+
[8.731481313705444,"o","\u001b[1m\u001b[97mcomponent number\u001b[m\u001b[K"]
38+
[8.814936637878418,"o"," "]
39+
[8.982696294784546,"o","d"]
40+
[9.087361097335815,"o","o"]
41+
[9.151376247406006,"o","u"]
42+
[9.383987665176392,"o","b"]
43+
[9.574780225753784,"o","l"]
44+
[9.70450234413147,"o","\u001b[25l\u001b[2;27H\u001b[?25h"]
45+
[9.718122243881226,"o","\u001b[1m\u001b[97m double\u001b[m\u001b[K"]
46+
[9.928346157073975,"o","\r"]
47+
[9.95093560218811,"o","\u001b[?2004l\r\n"]
48+
[10.007387638092041,"o","\u001b[?25l"]
49+
[10.075207471847534,"o","\u001b[1m\u001b[92m?\u001b[m \u001b[1m\u001b[97mEnter value\u001b[m \u001b[34m[Number Type: Double][Default \u001b[m99.9\u001b[34m]"]
50+
[10.091434478759766,"o","\u001b[m"]
51+
[12.732241153717041,"o","\u001b[3;15H5\u001b[70X\u001b[70C\u001b[K\u001b[35C"]
52+
[13.092545509338379,"o","\u001b[3;16H.\u001b[70X\u001b[70C\u001b[K\u001b[34C"]
53+
[13.577228307723999,"o","\u001b[3;17H5\u001b[70X\u001b[70C\u001b[K\u001b[33C"]
54+
[14.40083646774292,"o","\u001b[?2004h\u001b[1m\u001b[92m\r?\u001b[m \u001b[1m\u001b[97mEnter value\u001b[m \u001b[34m5.5\u001b[m\u001b[K\r\nGot value 5.5\u001b[K\u001b[33m\r\nmy-shell:>\u001b[m\u001b[K\u001b[?25h"]
55+
[15.966568946838379,"o","\u001b[31m"]

spring-shell-docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
** xref:components/ui/index.adoc[]
5050
*** xref:components/ui/render.adoc[]
5151
*** xref:components/ui/stringinput.adoc[]
52+
*** xref:components/ui/numberinput.adoc[]
5253
*** xref:components/ui/pathinput.adoc[]
5354
*** xref:components/ui/pathsearch.adoc[]
5455
*** xref:components/ui/confirmation.adoc[]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[[using-shell-components-ui-numberinput]]
2+
= Number Input
3+
4+
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
5+
6+
The number input component asks a user for simple number input. It can be configured to use any implementation of Number.class. The following listing shows an example:
7+
8+
[source, java, indent=0]
9+
----
10+
include::{snippets}/UiComponentSnippets.java[tag=snippet10]
11+
----
12+
13+
The following image shows typical output from a number input component:
14+
15+
[asciinema,rows=6]
16+
----
17+
include::example$component-number-input-1.cast[]
18+
----
19+
20+
The context object is `NumberInputContext`. The following table lists its context variables:
21+
22+
[[numberinputcontext-template-variables]]
23+
.NumberInputContext Template Variables
24+
|===
25+
|Key |Description
26+
27+
|`defaultValue`
28+
|The default value, if set. Otherwise, null.
29+
30+
|`defaultClass`
31+
|The default number class to use, if set. Otherwise, Integer.class.
32+
33+
|`required`
34+
|`true` if the input is required. Otherwise, false.
35+
36+
|`model`
37+
|The parent context variables (see xref:components/ui/render.adoc#textcomponentcontext-template-variables[TextComponentContext Template Variables]).
38+
|===

spring-shell-docs/src/test/java/org/springframework/shell/docs/FlowComponentSnippets.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public void runFlow() {
4545
.withStringInput("field2")
4646
.name("Field2")
4747
.and()
48+
.withNumberInput("number1")
49+
.name("Number1")
50+
.and()
51+
.withNumberInput("number2")
52+
.name("Number2")
53+
.defaultValue(20.5)
54+
.numberClass(Double.class)
55+
.and()
4856
.withConfirmationInput("confirmation1")
4957
.name("Confirmation1")
5058
.and()

spring-shell-docs/src/test/java/org/springframework/shell/docs/UiComponentSnippets.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424

2525
import org.jline.utils.AttributedString;
2626
import org.jline.utils.AttributedStringBuilder;
27-
2827
import org.springframework.shell.component.ConfirmationInput;
28+
import org.springframework.shell.component.ConfirmationInput.ConfirmationInputContext;
2929
import org.springframework.shell.component.MultiItemSelector;
30+
import org.springframework.shell.component.MultiItemSelector.MultiItemSelectorContext;
31+
import org.springframework.shell.component.NumberInput;
32+
import org.springframework.shell.component.NumberInput.NumberInputContext;
3033
import org.springframework.shell.component.PathInput;
3134
import org.springframework.shell.component.PathSearch;
3235
import org.springframework.shell.component.SingleItemSelector;
36+
import org.springframework.shell.component.SingleItemSelector.SingleItemSelectorContext;
3337
import org.springframework.shell.component.StringInput;
3438
import org.springframework.shell.component.ConfirmationInput.ConfirmationInputContext;
3539
import org.springframework.shell.component.MultiItemSelector.MultiItemSelectorContext;
@@ -238,4 +242,21 @@ public String pathSearch() {
238242
}
239243
}
240244
}
245+
246+
class Dump9 {
247+
// tag::snippet10[]
248+
@ShellComponent
249+
public class ComponentCommands extends AbstractShellComponent {
250+
251+
@ShellMethod(key = "component number", value = "Number input", group = "Components")
252+
public String numberInput() {
253+
NumberInput component = new NumberInput(getTerminal(), "Enter value", 99.9, Double.class);
254+
component.setResourceLoader(getResourceLoader());
255+
component.setTemplateExecutor(getTemplateExecutor());
256+
NumberInputContext context = component.run(NumberInputContext.empty());
257+
return "Got value " + context.getResultValue();
258+
}
259+
}
260+
// end::snippet10[]
261+
}
241262
}

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
@@ -62,8 +62,8 @@ public String stringInput(boolean mask) {
6262
}
6363

6464
@ShellMethod(key = "component number", value = "Number input", group = "Components")
65-
public String numberInput(Number defaultValue) {
66-
NumberInput component = new NumberInput(getTerminal(), "Enter value", defaultValue);
65+
public String numberInput() {
66+
NumberInput component = new NumberInput(getTerminal(), "Enter value");
6767
component.setResourceLoader(getResourceLoader());
6868
component.setTemplateExecutor(getTemplateExecutor());
6969
NumberInputContext context = component.run(NumberInputContext.empty());

0 commit comments

Comments
 (0)