Skip to content

Commit 025fd07

Browse files
Update documentation with new annotations
Closes #1166 Signed-off-by: Pablodev <[email protected]>
1 parent ff73bdc commit 025fd07

File tree

11 files changed

+48
-55
lines changed

11 files changed

+48
-55
lines changed

README.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ Here is a quick teaser of a complete Spring Shell application in Java:
2727
----
2828
import org.springframework.boot.SpringApplication;
2929
import org.springframework.boot.autoconfigure.SpringBootApplication;
30-
import org.springframework.shell.standard.ShellComponent;
31-
import org.springframework.shell.standard.ShellMethod;
30+
import org.springframework.shell.command.annotation.Command;
3231
3332
@SpringBootApplication
34-
@ShellComponent
33+
@Command
3534
public class DemoApplication {
3635
37-
@ShellMethod
36+
@Command
3837
public String hi() {
3938
return "hi";
4039
}

spring-shell-docs/modules/ROOT/pages/commands/exceptionhandling/annotation.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
55

6-
`@ShellComponent` classes can have `@ExceptionResolver` methods to handle exceptions from component
6+
`@Command` classes can have `@ExceptionResolver` methods to handle exceptions from component
77
methods. These are meant for annotated methods.
88

99
The exception may match against a top-level exception being propagated (e.g. a direct `IOException`

spring-shell-docs/modules/ROOT/pages/commands/interactionmode.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can define the interaction mode with `CommandRegisration`:
1414
include::{snippets}/CommandRegistrationInteractionModeSnippets.java[tag=snippet1]
1515
----
1616

17-
Or with `@ShellMethod`.
17+
Or with `@Command`.
1818

1919
[source, java, indent=0]
2020
----

spring-shell-docs/modules/ROOT/pages/commands/organize.adoc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,36 @@ To alleviate this possible confusion, Spring Shell provides the ability to group
1010
with reasonable defaults. Related commands would then end up in the same group (for example, `User Management Commands`)
1111
and be displayed together in the help screen and other places.
1212

13-
By default, commands are grouped according to the class they are implemented in,
14-
turning the camelCase class name into separate words (so `URLRelatedCommands` becomes `URL Related Commands`).
15-
This is a sensible default, as related commands are often already in the class anyway,
16-
because they need to use the same collaborating objects.
13+
By default, commands are grouped into the `Default` group. However, you can override the group for
14+
a command in the following ways, in order of priority:
1715

18-
If, however, this behavior does not suit you, you can override the group for a
19-
command in the following ways, in order of priority:
16+
. Specify a `group()` in the `@Command` annotation on the method.
2017

21-
. Specify a `group()` in the `@ShellMethod` annotation.
22-
. Place a `@ShellCommandGroup` on the class in which the command is defined. This applies
18+
. Specify a `group()` in the `@Command` annotation on the class in which the command is defined. This applies
2319
the group for all commands defined in that class (unless overridden, as explained earlier).
24-
. Place a `@ShellCommandGroup` on the package (through `package-info.java`)
25-
in which the command is defined. This applies to all the commands defined in the
26-
package (unless overridden at the method or class level, as explained earlier).
2720

2821
The following listing shows an example:
2922

3023
[source,java]
3124
----
25+
@Command
3226
public class UserCommands {
33-
@ShellMethod(value = "This command ends up in the 'User Commands' group")
27+
@Command(description = "This command ends up in the 'Default' group")
3428
public void foo() {}
3529
36-
@ShellMethod(value = "This command ends up in the 'Other Commands' group",
30+
@Command(description = "This command ends up in the 'Other Commands' group",
3731
group = "Other Commands")
3832
public void bar() {}
3933
}
4034
4135
...
4236
43-
@ShellCommandGroup("Other Commands")
37+
@Command(group = "Other Commands")
4438
public class SomeCommands {
45-
@ShellMethod(value = "This one is in 'Other Commands'")
39+
@Command(description = "This one is in 'Other Commands'")
4640
public void wizz() {}
4741
48-
@ShellMethod(value = "And this one is 'Yet Another Group'",
42+
@Command(description = "And this one is 'Yet Another Group'",
4943
group = "Yet Another Group")
5044
public void last() {}
5145
}

spring-shell-docs/modules/ROOT/pages/commands/writing.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ It's possible to autowire `Terminal` to get access to its writer.
2929

3030
[source, java, indent=0]
3131
----
32-
include::{snippets}/WritingSnippets.java[tag=legacyanno-terminal-writer]
32+
include::{snippets}/WritingSnippets.java[tag=inject-terminal-writer]
3333
----

spring-shell-docs/modules/ROOT/pages/completion.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ include::{snippets}/CompletionSnippets.java[tag=builder-1]
3737
----
3838

3939
Option values with annotation based command registration are handled
40-
via `ValueProvider` interface which can be defined with `@ShellOption`
40+
via `CompletionProvider` interface which can be defined with `@OptionValues`
4141
annotation.
4242

4343
[source, java, indent=0]
4444
----
4545
include::{snippets}/CompletionSnippets.java[tag=provider-1]
4646
----
4747

48-
Actual `ValueProvider` with annotation based command needs to be
48+
Actual `CompletionProvider` with annotation based command needs to be
4949
registered as a _Bean_.
5050

5151
[source, java, indent=0]

spring-shell-docs/modules/ROOT/pages/execution.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Some commands may not have any useful meanings when they run in interactive mode
2020
or (conversely) in non-interactive mode. For example, a built-in `exit` command would
2121
have no meaning in non-interactive mode, because it is used to exit interactive mode.
2222

23-
The `@ShellMethod` annotation has a field called `interactionMode` that you can use to inform
23+
The `@Command` annotation has a field called `interactionMode` that you can use to inform
2424
shell about when a particular command is available.
2525

2626
[[using-shell-execution-shellrunner]]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package org.springframework.shell.docs;
1717

1818
import org.springframework.shell.command.CommandRegistration;
19+
import org.springframework.shell.command.annotation.Command;
1920
import org.springframework.shell.context.InteractionMode;
20-
import org.springframework.shell.standard.ShellMethod;
2121

2222
public class CommandRegistrationInteractionModeSnippets {
2323

@@ -38,7 +38,7 @@ CommandRegistration commandRegistration() {
3838
static class Dump1 {
3939

4040
// tag::snippet2[]
41-
@ShellMethod(key = "mycommand", interactionMode = InteractionMode.INTERACTIVE)
41+
@Command(command = "mycommand", interactionMode = InteractionMode.INTERACTIVE)
4242
public void mycommand() {
4343
}
4444
// end::snippet2[]

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import org.springframework.shell.CompletionContext;
2323
import org.springframework.shell.CompletionProposal;
2424
import org.springframework.shell.command.CommandRegistration;
25+
import org.springframework.shell.command.annotation.Command;
26+
import org.springframework.shell.command.annotation.Option;
27+
import org.springframework.shell.command.annotation.OptionValues;
28+
import org.springframework.shell.completion.CompletionProvider;
2529
import org.springframework.shell.completion.CompletionResolver;
26-
import org.springframework.shell.standard.ShellMethod;
27-
import org.springframework.shell.standard.ShellOption;
28-
import org.springframework.shell.standard.ValueProvider;
2930

3031
public class CompletionSnippets {
3132

@@ -57,10 +58,10 @@ public List<CompletionProposal> apply(CompletionContext t) {
5758
// end::resolver-1[]
5859

5960
// tag::provider-1[]
60-
static class MyValuesProvider implements ValueProvider {
61+
static class MyCompletionProvider implements CompletionProvider {
6162

6263
@Override
63-
public List<CompletionProposal> complete(CompletionContext completionContext) {
64+
public List<CompletionProposal> apply(CompletionContext completionContext) {
6465
return Arrays.asList("val1", "val2").stream()
6566
.map(CompletionProposal::new)
6667
.collect(Collectors.toList());
@@ -70,9 +71,9 @@ public List<CompletionProposal> complete(CompletionContext completionContext) {
7071

7172
static class Dump1 {
7273
// tag::anno-method[]
73-
@ShellMethod(value = "complete", key = "complete")
74+
@Command(command = "complete", description = "complete")
7475
public String complete(
75-
@ShellOption(valueProvider = MyValuesProvider.class) String arg1)
76+
@Option @OptionValues(provider = "myCompletionProvider") String arg1)
7677
{
7778
return "You said " + arg1;
7879
}

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jline.utils.AttributedString;
2626
import org.jline.utils.AttributedStringBuilder;
2727

28+
import org.springframework.shell.command.annotation.Command;
2829
import org.springframework.shell.component.ConfirmationInput;
2930
import org.springframework.shell.component.MultiItemSelector;
3031
import org.springframework.shell.component.PathInput;
@@ -40,8 +41,6 @@
4041
import org.springframework.shell.component.StringInput.StringInputContext;
4142
import org.springframework.shell.component.support.SelectorItem;
4243
import org.springframework.shell.standard.AbstractShellComponent;
43-
import org.springframework.shell.standard.ShellComponent;
44-
import org.springframework.shell.standard.ShellMethod;
4544
import org.springframework.util.StringUtils;
4645

4746
public class UiComponentSnippets {
@@ -72,7 +71,7 @@ public List<AttributedString> apply(StringInputContext context) {
7271

7372
class Dump1 extends AbstractShellComponent {
7473
// tag::snippet2[]
75-
@ShellMethod(key = "component stringcustom", value = "String input", group = "Components")
74+
@Command(command = "component stringcustom", description = "String input", group = "Components")
7675
public String stringInputCustom(boolean mask) {
7776
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue",
7877
new StringInputCustomRenderer());
@@ -89,10 +88,10 @@ public String stringInputCustom(boolean mask) {
8988

9089
class Dump2 {
9190
// tag::snippet3[]
92-
@ShellComponent
91+
@Command
9392
public class ComponentCommands extends AbstractShellComponent {
9493

95-
@ShellMethod(key = "component string", value = "String input", group = "Components")
94+
@Command(command = "component string", description = "String input", group = "Components")
9695
public String stringInput(boolean mask) {
9796
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
9897
component.setResourceLoader(getResourceLoader());
@@ -109,10 +108,10 @@ public String stringInput(boolean mask) {
109108

110109
class Dump3 {
111110
// tag::snippet4[]
112-
@ShellComponent
111+
@Command
113112
public class ComponentCommands extends AbstractShellComponent {
114113

115-
@ShellMethod(key = "component path input", value = "Path input", group = "Components")
114+
@Command(command = "component path input", description = "Path input", group = "Components")
116115
public String pathInput() {
117116
PathInput component = new PathInput(getTerminal(), "Enter value");
118117
component.setResourceLoader(getResourceLoader());
@@ -126,10 +125,10 @@ public String pathInput() {
126125

127126
class Dump4 {
128127
// tag::snippet5[]
129-
@ShellComponent
128+
@Command
130129
public class ComponentCommands extends AbstractShellComponent {
131130

132-
@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
131+
@Command(command = "component confirmation", description = "Confirmation input", group = "Components")
133132
public String confirmationInput(boolean no) {
134133
ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
135134
component.setResourceLoader(getResourceLoader());
@@ -143,10 +142,10 @@ public String confirmationInput(boolean no) {
143142

144143
class Dump5 {
145144
// tag::snippet6[]
146-
@ShellComponent
145+
@Command
147146
public class ComponentCommands extends AbstractShellComponent {
148147

149-
@ShellMethod(key = "component single", value = "Single selector", group = "Components")
148+
@Command(command = "component single", description = "Single selector", group = "Components")
150149
public String singleSelector() {
151150
SelectorItem<String> i1 = SelectorItem.of("key1", "value1");
152151
SelectorItem<String> i2 = SelectorItem.of("key2", "value2");
@@ -166,10 +165,10 @@ public String singleSelector() {
166165

167166
class Dump6 {
168167
// tag::snippet7[]
169-
@ShellComponent
168+
@Command
170169
public class ComponentCommands extends AbstractShellComponent {
171170

172-
@ShellMethod(key = "component multi", value = "Multi selector", group = "Components")
171+
@Command(command = "component multi", description = "Multi selector", group = "Components")
173172
public String multiSelector() {
174173
List<SelectorItem<String>> items = new ArrayList<>();
175174
items.add(SelectorItem.of("key1", "value1"));
@@ -191,10 +190,10 @@ public String multiSelector() {
191190
}
192191

193192
class Dump7 {
194-
@ShellComponent
193+
@Command
195194
public class ComponentCommands extends AbstractShellComponent {
196195

197-
@ShellMethod(key = "component single", value = "Single selector", group = "Components")
196+
@Command(command = "component single", description = "Single selector", group = "Components")
198197
public String singleSelector() {
199198
// tag::snippet8[]
200199
SelectorItem<String> i1 = SelectorItem.of("key1", "value1");
@@ -215,10 +214,10 @@ public String singleSelector() {
215214
}
216215

217216
class Dump8 {
218-
@ShellComponent
217+
@Command
219218
public class ComponentCommands extends AbstractShellComponent {
220219

221-
@ShellMethod(key = "component path input", value = "Path search", group = "Components")
220+
@Command(command = "component path input", description = "Path search", group = "Components")
222221
public String pathSearch() {
223222
// tag::snippet9[]
224223
PathSearchConfig config = new PathSearch.PathSearchConfig();

0 commit comments

Comments
 (0)