Execution
This section describes how to run Spring Shell in interactive or non-interactive mode.
Interaction Mode
Version 2.1.x introduced built-in support to distinguish between interactive and non-interactive modes. This makes it easier to use the shell as a simple command-line tool without requiring customization.
Interactive mode is enabled by default, including when command-line arguments are supplied.
To execute a command from the process arguments, set spring.shell.interactive.enabled=false.
This is useful for command-line tools, including applications compiled with Native Support.
Some commands may not have any useful meanings when they run in interactive mode
or (conversely) in non-interactive mode. For example, a built-in exit command would
have no meaning in non-interactive mode, because it is used to exit interactive mode.
Shell Runners
ShellRunner is the main interface to run a shell. There can be only one ShellRunner
per application context.
Three ShellRunner implementations exist, named SystemShellRunner,
JLineShellRunner, and NonInteractiveShellRunner. With the Spring Shell starter,
interactive mode uses JLineShellRunner. Without JLine on the classpath,
it uses SystemShellRunner.
To enable non-interactive mode, you can set the spring.shell.interactive.enabled
property to false. This will switch the ShellRunner implementation to
NonInteractiveShellRunner.
In a Spring Boot application, Spring Shell registers an ApplicationRunner bean named springShellApplicationRunner
that invokes the configured ShellRunner. To customize the application startup logic,
provide your own ApplicationRunner bean with that name.
|
Debug Mode
Spring Shell provides a debug mode that can be enabled by setting the
spring.shell.debug.enabled property to true. When enabled, this mode
provides additional debugging information in interactive mode by printing
stack traces of errors, which can be useful for troubleshooting and development purposes.