Skip to content

Commit 1dc6797

Browse files
committed
Update documentation
1 parent 6b75609 commit 1dc6797

File tree

13 files changed

+81
-114
lines changed

13 files changed

+81
-114
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
* xref:basics/index.adoc[]
55
** xref:basics/reading.adoc[]
66
* xref:commands/index.adoc[]
7-
** xref:commands/registration/index.adoc[]
8-
** xref:commands/registration/programmatic.adoc[]
9-
** xref:commands/registration/annotation.adoc[]
7+
** xref:commands/registration.adoc[]
108
** xref:commands/organize.adoc[]
119
** xref:commands/syntax.adoc[]
1210
** xref:commands/validation.adoc[]

spring-shell-docs/modules/ROOT/pages/basics/reading.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
Throughout this documentation, we make references to configuring something by using
66
annotations or programmatic examples.
77

8-
The annotation model relates to the use of `@Command`.
8+
The annotation model relates to the use of `@Command` annotation. The programmatic model relates to creating commands using APIs such as `Command.Builder`.
99

10-
The programmatic model relates to creating commands using APIs such as `Command.Builder`.
11-
12-
These approaches can be mixed in the same application.
10+
These two approaches can be mixed in the same application.

spring-shell-docs/modules/ROOT/pages/commands/builtin/help.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Typing `help` + `ENTER` lists all the commands known to the shell and a short de
1010
[source, bash]
1111
----
1212
my-shell:>help
13-
AVAILABLE COMMANDS
13+
Available commands:
1414
1515
Built-In Commands
1616
help: Display help about available commands
1717
clear: Clear the shell screen.
1818
version: Show version info
1919
----
2020

21-
Typing `<command> -h` `<command> --help` or shows more detailed information about a command, including the available parameters, their
21+
Typing `<command> -h` or `<command> --help` shows more information about a command, including the available parameters, their
2222
type, whether they are mandatory or not, and other details.

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

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

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

7-
In this section, we go through an actual command definition and parsing rules.
7+
In this section, we go through the actual command definition and parsing rules.
88

99

1010

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[[registration]]
2+
= Command Registration
3+
:page-section-summary-toc: 1
4+
5+
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
6+
7+
There are two different ways to define a command, through an annotation model and through a programmatic model:
8+
9+
- In the annotation model, you define your methods in a `@Component` class and the methods with specific annotations.
10+
- In the programmatic model, you use a more low level approach, defining commands as beans.
11+
12+
[[commands-registration-annotation]]
13+
== Annotation-Based Registration
14+
15+
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
16+
17+
The `@Command` annotation marks a method as a candidate for command registration.
18+
In below example a command `example` is defined.
19+
20+
[source, java, indent=0]
21+
----
22+
include::{snippets}/CommandAnnotationSnippets.java[tag=command-anno-in-method]
23+
----
24+
25+
TIP: The command name optional, if not provided the method name will be used as command name.
26+
When the command returns a value, it will be printed to the shell output.
27+
28+
Using a `@Command` will not automatically register command targets, instead it is required to use
29+
`@EnableCommand` annotations. This model is familiar from other parts of Spring umbrella and
30+
provides better flexibility for a user being inclusive rather than exclusive for command targets.
31+
32+
You can define target classes using `@EnableCommand`. It will get picked from all _Configuration_
33+
classes.
34+
35+
[source, java, indent=0]
36+
----
37+
include::{snippets}/CommandAnnotationSnippets.java[tag=enablecommand-with-class]
38+
----
39+
40+
TIP: `@EnableCommand` is not required in a Spring Boot application, as Spring Boot auto-configuration
41+
will take care of that.
42+
43+
[[commands-registration-programmatic]]
44+
== Programmatic Registration
45+
46+
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
47+
48+
In the programmatic model, commands can be defined as beans of type `Command`:
49+
50+
[source, java, indent=0]
51+
----
52+
include::{snippets}/CommandRegistrationBeanSnippets.java[tag=plain]
53+
----
54+
55+
You can also use the `AbstractCommand` class to simplify command definitions:
56+
57+
[source, java, indent=0]
58+
----
59+
include::{snippets}/CommandRegistrationBeanSnippets.java[tag=abstractcommand]
60+
----
61+
62+
`AbstractCommand` provides some utility methods to simplify command creation like
63+
handling help options (`-h` and `--help`) and printing messages to the shell output.

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

spring-shell-docs/modules/ROOT/pages/commands/registration/index.adoc

Lines changed: 0 additions & 14 deletions
This file was deleted.

spring-shell-docs/modules/ROOT/pages/commands/registration/programmatic.adoc

Lines changed: 0 additions & 21 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[syntax]]
2-
= Command syntax
2+
= Command Syntax
33

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[writing]]
2-
= Writing
2+
= Writing Output
33

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

0 commit comments

Comments
 (0)