Skip to content

Commit cde73ec

Browse files
committed
Update docs
1 parent 6c2e858 commit cde73ec

File tree

2 files changed

+91
-32
lines changed

2 files changed

+91
-32
lines changed

spring-shell-docs/src/main/asciidoc/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ include::what-is-spring-shell.adoc[]
2121

2222
include::using-spring-shell.adoc[]
2323

24-
include::extending-spring-shell.adoc[]
24+
// include::extending-spring-shell.adoc[]

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

Lines changed: 90 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
This section describes how to use Spring Shell.
66

7+
[IMPORTANT]
8+
====
9+
_Spring Shell 3.x_ is a major rework to bring codebase up-to-date with
10+
existing _Spring Boot_ versions, adding new features and especially
11+
making it work with _GraalVM_ which makes command-line applications much
12+
more relevant on a java space. Moving to new major version also allows
13+
us to clean up codebase and make some needed breaking changes.
14+
====
15+
716
=== Getting Started
817

918
To see what Spring Shell has to offer, we can write a trivial shell application that
@@ -106,15 +115,6 @@ https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-featu
106115
====
107116
[source]
108117
----
109-
110-
. ____ _ __ _ _
111-
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
112-
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
113-
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
114-
' |____| .__|_| |_|_| |_\__, | / / / /
115-
=========|_|==============|___/=/_/_/_/
116-
:: Spring Boot :: (v1.5.6.RELEASE)
117-
118118
shell:>
119119
----
120120
====
@@ -545,9 +545,9 @@ a reverse search, `Ctrl+a`] and `Ctrl+e` to move to the beginning and the end of
545545
`Esc b` to move forward or backward (respectively) one word at a time.
546546

547547
[[providing-tab-completion]]
548-
===== Providing TAB Completion Proposals
548+
// ===== Providing TAB Completion Proposals
549549

550-
TBD
550+
// TBD
551551

552552
[[validating-command-arguments]]
553553
=== Validating Command Arguments
@@ -794,7 +794,7 @@ You can override or disable these commands individually (see <<overriding-or-dis
794794
However, if they are not overridden or disabled, this section describes their behavior.
795795

796796
[[help-command]]
797-
==== Integrated Documentation with the `help` Command
797+
==== Help
798798

799799
Running a shell application often implies that the user is in a graphically limited
800800
environment. Also, while we are nearly always connected in the era of mobile phones,
@@ -849,17 +849,17 @@ OPTIONS
849849
----
850850
====
851851

852-
==== Clearing the Screen
852+
==== Clear
853853
The `clear` command does what you would expect and clears the screen, resetting the prompt
854854
in the top left corner.
855855

856-
==== Exiting the Shell
856+
==== Exit
857857

858858
The `quit` command (also aliased as `exit`) requests the shell to quit, gracefully
859859
closing the Spring application context. If not overridden, a JLine `History` bean writes a history of all
860860
commands to disk, so that they are available again (see <<interacting-with-the-shell>>) on the next launch.
861861

862-
==== Displaying Details about an Error
862+
==== Stacktrace
863863

864864
When an exception occurs inside command code, it is caught by the shell and a simple, one-line message is displayed
865865
so as not to overflow the user with too much information.
@@ -869,13 +869,73 @@ To this end, Spring Shell remembers the last exception that occurred, and the us
869869
command to print all the details on the console.
870870

871871
[[script-command]]
872-
==== Running a Batch of Commands
872+
==== Script
873873

874874
The `script` command accepts a local file as an argument and replays commands found there, one at a time.
875875

876876
Reading from the file behaves exactly like inside the interactive shell, so lines starting with `//` are considered
877877
to be comments and are ignored, while lines ending with `\` trigger line continuation.
878878

879+
==== History
880+
881+
The `history` command shows history of a commands which has been executed.
882+
883+
==== Completion
884+
885+
The `completion` command set allows you to create _scripts_ files which can be used
886+
with am OS shell implementations to provide completion. This is very usefull when
887+
working with non-interactive mode.
888+
889+
Currently only implementation is for _bash_ which works with `bash` sub-command.
890+
891+
=== Interaction Mode
892+
893+
Starting from _3.x_ a build-in support has been added to distinguish between interactive
894+
and non-interactive modes. This has been added so that it's easier to use shell as a
895+
simple command-line tool without requiring customisation to accomplish that.
896+
897+
Currently interactive mode is entered if any command line options are passed when starting
898+
or running a shell from a command-line. This especially works well when shell application
899+
is compiled with <<native>>.
900+
901+
Some commands may not have any usefull meaning if running on interactive mode
902+
or vice versa on non-interactive mode. For example a build-in `exit` command
903+
have no meaning in non-interactive mode as it's used to exit interactive mode.
904+
905+
Annotation `@ShellMethod` has a field `interactionMode` which can be used to instruct
906+
shell when particular command is available.
907+
908+
[[native]]
909+
=== Native Support
910+
911+
Re-work with _3.x_ brings in an experimental support for compiling shell application
912+
into _native_ application with _GraalVM_ and _spring-native_. As underlying _jline_
913+
library works with _GraalVM_ most of a things should just work.
914+
915+
Project can be compiled with native profile to get sample compiled as an native
916+
application:
917+
918+
====
919+
----
920+
$ ./mvnw clean package -Pnative
921+
----
922+
====
923+
924+
You can then run sample either with interactive or non-interactive mode:
925+
926+
====
927+
----
928+
$ ./spring-shell-samples/target/spring-shell-samples help
929+
AVAILABLE COMMANDS
930+
931+
Built-In Commands
932+
completion bash: Generate bash completion script
933+
help: Display help about available commands.
934+
history: Display or save the history of previously run commands
935+
script: Read and execute commands from a file.
936+
...
937+
----
938+
====
879939

880940
=== Customizing the Shell
881941

@@ -960,9 +1020,9 @@ Alternatively, before making any changes on your own, you can open an issue with
9601020
always welcome!
9611021
====
9621022

963-
==== ResultHandlers
1023+
// ==== ResultHandlers
9641024

965-
TBD
1025+
// TBD
9661026

9671027
==== PromptProvider
9681028
After each command invocation, the shell waits for new input from the user, displaying
@@ -1011,23 +1071,22 @@ public class CustomPromptProvider implements PromptProvider {
10111071
====
10121072

10131073
==== Customizing Command Line Options Behavior
1014-
Spring Shell comes with two default Spring Boot `ApplicationRunners`:
1015-
1016-
* `InteractiveShellApplicationRunner` bootstraps the Shell REPL. It sets up the JLine infrastructure and eventually
1017-
calls `Shell.run()`
1018-
* `ScriptShellApplicationRunner` looks for program arguments that start with `@`, assumes those are local file names and
1019-
tries to run commands contained in those files (with the same semantics as the <<script-command,script command>>) and
1020-
then exits the process (by effectively disabling the `InteractiveShellApplicationRunner` -- see below).
10211074

1022-
If this behavior does not suit you, provide at least one bean of type `ApplicationRunner`
1023-
and optionally disable the standard ones. You can take inspiration from the `ScriptShellApplicationRunner`:
1075+
There can be exactly one shell spesific `ShellApplicationRunner` which simply extends
1076+
Boot's `ApplicationRunner`. Default behariour is to have actual runner logic in
1077+
various `ShellRunner` implementations where candidate will be picked up.
10241078

1079+
[IMPORTANT]
1080+
====
1081+
This is a breaking change in `3.x` as previous shell versions had an confusing
1082+
logic how `ApplicationRunner` instances were used. These changes were made
1083+
to have a better support for interactive and non-interactive modes in a same
1084+
shell application as it's convenient to fully work on command-line and still
1085+
have ability to enter interactive mode.
10251086
====
1026-
[source,java]
1027-
----
1028-
include::../../../../spring-shell-core/src/main/java/org/springframework/shell/jline/ScriptShellApplicationRunner.java[tag=documentation]
10291087

1030-
...
1088+
You can override bean type of `ShellApplicationRunner` if there's a need to
1089+
customise shell running logic.
10311090
----
10321091
====
10331092

0 commit comments

Comments
 (0)