[[using-shell-execution]]
= Execution

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

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

[[using-shell-execution-interactionmode]]
== 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.

Currently, interactive mode is entered if any command line options are passed when starting
or running a shell from a command line. This works especially well when a shell application
is compiled with xref:building.adoc#native[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.

The `@ShellMethod` annotation has a field called `interactionMode` that you can use to inform
shell about when a particular command is available.

[[using-shell-execution-shellrunner]]
== Shell Runners

`ShellApplicationRunner` is a main interface where Boot's `ApplicationArguments` are passed
and its default implementation makes a choice which `ShellRunner` is used. There can be
only one `ShellApplicationRunner` but it can be redefined if needed for some reason.

Three `ShellRunner` implementation exists, named `InteractiveShellRunner`,
`NonInteractiveShellRunner` and `ScriptShellRunner`. Only `NonInteractiveShellRunner`
is enabled by default. Enabled state can be modified using properties
`spring.shell.interactive.enabled`, `spring.shell.noninteractive.enabled` and
`spring.shell.script.enabled` respecively.

For example enabling interactive and script runners use properties:

[source, yaml]
----
spring:
  shell:
    interactive:
      enabled: true
    script:
      enabled: true
----

NOTE: Versions up to `3.2.x` had all runners enabled by default, starting from `3.3.x`
      only `NonInteractiveShellRunner` is enabled by default.
