4
4
5
5
This section describes how to use Spring Shell.
6
6
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
+
7
16
=== Getting Started
8
17
9
18
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
106
115
====
107
116
[source]
108
117
----
109
-
110
- . ____ _ __ _ _
111
- /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
112
- ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
113
- \\/ ___)| |_)| | | | | || (_| | ) ) ) )
114
- ' |____| .__|_| |_|_| |_\__, | / / / /
115
- =========|_|==============|___/=/_/_/_/
116
- :: Spring Boot :: (v1.5.6.RELEASE)
117
-
118
118
shell:>
119
119
----
120
120
====
@@ -545,9 +545,9 @@ a reverse search, `Ctrl+a`] and `Ctrl+e` to move to the beginning and the end of
545
545
`Esc b` to move forward or backward (respectively) one word at a time.
546
546
547
547
[[providing-tab-completion]]
548
- ===== Providing TAB Completion Proposals
548
+ // ===== Providing TAB Completion Proposals
549
549
550
- TBD
550
+ // TBD
551
551
552
552
[[validating-command-arguments]]
553
553
=== Validating Command Arguments
@@ -794,7 +794,7 @@ You can override or disable these commands individually (see <<overriding-or-dis
794
794
However, if they are not overridden or disabled, this section describes their behavior.
795
795
796
796
[[help-command]]
797
- ==== Integrated Documentation with the `help` Command
797
+ ==== Help
798
798
799
799
Running a shell application often implies that the user is in a graphically limited
800
800
environment. Also, while we are nearly always connected in the era of mobile phones,
@@ -849,17 +849,17 @@ OPTIONS
849
849
----
850
850
====
851
851
852
- ==== Clearing the Screen
852
+ ==== Clear
853
853
The `clear` command does what you would expect and clears the screen, resetting the prompt
854
854
in the top left corner.
855
855
856
- ==== Exiting the Shell
856
+ ==== Exit
857
857
858
858
The `quit` command (also aliased as `exit`) requests the shell to quit, gracefully
859
859
closing the Spring application context. If not overridden, a JLine `History` bean writes a history of all
860
860
commands to disk, so that they are available again (see <<interacting-with-the-shell>>) on the next launch.
861
861
862
- ==== Displaying Details about an Error
862
+ ==== Stacktrace
863
863
864
864
When an exception occurs inside command code, it is caught by the shell and a simple, one-line message is displayed
865
865
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
869
869
command to print all the details on the console.
870
870
871
871
[[script-command]]
872
- ==== Running a Batch of Commands
872
+ ==== Script
873
873
874
874
The `script` command accepts a local file as an argument and replays commands found there, one at a time.
875
875
876
876
Reading from the file behaves exactly like inside the interactive shell, so lines starting with `//` are considered
877
877
to be comments and are ignored, while lines ending with `\` trigger line continuation.
878
878
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
+ ====
879
939
880
940
=== Customizing the Shell
881
941
@@ -960,9 +1020,9 @@ Alternatively, before making any changes on your own, you can open an issue with
960
1020
always welcome!
961
1021
====
962
1022
963
- ==== ResultHandlers
1023
+ // ==== ResultHandlers
964
1024
965
- TBD
1025
+ // TBD
966
1026
967
1027
==== PromptProvider
968
1028
After each command invocation, the shell waits for new input from the user, displaying
@@ -1011,23 +1071,22 @@ public class CustomPromptProvider implements PromptProvider {
1011
1071
====
1012
1072
1013
1073
==== 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).
1021
1074
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.
1024
1078
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.
1025
1086
====
1026
- [source,java]
1027
- ----
1028
- include::../../../../spring-shell-core/src/main/java/org/springframework/shell/jline/ScriptShellApplicationRunner.java[tag=documentation]
1029
1087
1030
- ...
1088
+ You can override bean type of `ShellApplicationRunner` if there's a need to
1089
+ customise shell running logic.
1031
1090
----
1032
1091
====
1033
1092
0 commit comments