Skip to content

Commit ff41b50

Browse files
committed
Docs about shell runners
- Relates #558
1 parent 2a3856c commit ff41b50

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[[commands-interactionmode]]
2+
=== Interaction Mode
3+
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
4+
5+
Command registration can define `InteractionMode` which is used to hide commands
6+
depending which mode shell is executing. More about that in <<using-shell-execution-interactionmode>>.
7+
8+
You can define it with `CommandRegisration`.
9+
10+
====
11+
[source, java, indent=0]
12+
----
13+
include::{snippets}/CommandRegistrationInteractionModeSnippets.java[tag=snippet1]
14+
----
15+
====
16+
17+
Or with `@ShellMethod`.
18+
19+
====
20+
[source, java, indent=0]
21+
----
22+
include::{snippets}/CommandRegistrationInteractionModeSnippets.java[tag=snippet2]
23+
----
24+
====

spring-shell-docs/src/main/asciidoc/using-shell-commands.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ include::using-shell-commands-availability.adoc[]
1414
include::using-shell-commands-exceptionhandling.adoc[]
1515

1616
include::using-shell-commands-hidden.adoc[]
17+
18+
include::using-shell-commands-interactionmode.adoc[]

spring-shell-docs/src/main/asciidoc/using-shell-execution.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
[[using-shell-execution]]
12
== Execution
3+
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
24

35
This section describes how to set up a Spring Shell to work in interactive mode.
46

7+
[[using-shell-execution-interactionmode]]
58
=== Interaction Mode
69

710
Version 2.1.x introduced built-in support to distinguish between interactive
@@ -18,3 +21,15 @@ have no meaning in non-interactive mode, because it is used to exit interactive
1821

1922
The `@ShellMethod` annotation has a field called `interactionMode` that you can use to inform
2023
shell about when a particular command is available.
24+
25+
[[using-shell-execution-shellrunner]]
26+
=== Shell Runners
27+
28+
`ShellApplicationRunner` is a main interface where Boot's `ApplicationArguments` are passed
29+
and its default implementation makes a choice which `ShellRunner` is used. There can be
30+
only one `ShellApplicationRunner` but it can be redefined if needed for some reason.
31+
32+
Three `ShellRunner` implementation exists, named `InteractiveShellRunner`,
33+
`NonInteractiveShellRunner` and `ScriptShellRunner`. These are enabled on default but
34+
can be disable if needed using properties `spring.shell.interactive.enabled`,
35+
`spring.shell.noninteractive.enabled` and `spring.shell.script.enabled` respecively.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.shell.docs;
17+
18+
import org.springframework.shell.command.CommandRegistration;
19+
import org.springframework.shell.context.InteractionMode;
20+
import org.springframework.shell.standard.ShellMethod;
21+
22+
public class CommandRegistrationInteractionModeSnippets {
23+
24+
// tag::snippet1[]
25+
CommandRegistration commandRegistration() {
26+
return CommandRegistration.builder()
27+
.command("mycommand")
28+
// can be defined for all modes
29+
.interactionMode(InteractionMode.ALL)
30+
// can be defined only for interactive
31+
.interactionMode(InteractionMode.INTERACTIVE)
32+
// can be defined only for non-interactive
33+
.interactionMode(InteractionMode.NONINTERACTIVE)
34+
.build();
35+
}
36+
// end::snippet1[]
37+
38+
static class Dump1 {
39+
40+
// tag::snippet2[]
41+
@ShellMethod(key = "mycommand", interactionMode = InteractionMode.INTERACTIVE)
42+
public void mycommand() {
43+
}
44+
// end::snippet2[]
45+
}
46+
47+
}

0 commit comments

Comments
 (0)