Update docs
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
[[using-shell-customization-commandnotfound]]
|
||||
= Command Not Found
|
||||
|
||||
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
|
||||
|
||||
On default a missing command is handled via `CommandNotFoundResultHandler`
|
||||
and outputs a simple message:
|
||||
|
||||
[source, text]
|
||||
----
|
||||
shell:>missing
|
||||
No command found for 'missing'
|
||||
----
|
||||
|
||||
Internally `CommandNotFoundResultHandler` is using `CommandNotFoundMessageProvider`
|
||||
which is a simple function taking a `ProviderContext` and returning a text
|
||||
message. Below is an example what a custom message provider might look like.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/CommandNotFoundSnippets.java[tag=custom-provider]
|
||||
----
|
||||
|
||||
It's possible to change this implementation by defining it as a bean.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/CommandNotFoundSnippets.java[tag=provider-bean-1]
|
||||
----
|
||||
|
||||
`CommandNotFoundResultHandler` is a functional interface so it can
|
||||
be writter as a lambda.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/CommandNotFoundSnippets.java[tag=provider-bean-2]
|
||||
----
|
||||
@@ -0,0 +1,25 @@
|
||||
[[using-shell-customization-contextclose]]
|
||||
= Context Close
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
|
||||
|
||||
Command execution logic happens via Spring Boot's `ApplicationRunner` beans.
|
||||
Normally Spring `ApplicationContext` closes automatically after these runner
|
||||
beans has been processed unless there is something what keeps it alive like
|
||||
use of `@EnableScheduling` or generally speaking there are threads which
|
||||
don't die automatically.
|
||||
|
||||
It is possible to add configuration property `spring.shell.context.close`
|
||||
which registers `ApplicationListener` for `ApplicationReadyEvent` and requests
|
||||
context close after shell has completed its execution logic.
|
||||
|
||||
[source, yaml]
|
||||
----
|
||||
spring:
|
||||
shell:
|
||||
context:
|
||||
close: true
|
||||
----
|
||||
|
||||
NOTE: This setting is not enabled by default.
|
||||
@@ -0,0 +1,9 @@
|
||||
[[using-shell-customization]]
|
||||
= Customization
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
This section describes how you can customize the shell.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
[[using-shell-customization-logging]]
|
||||
= Logging
|
||||
|
||||
On default a _Spring Boot_ application will log messages into a console which
|
||||
at minimum is annoying and may also mix output from a shell commands.
|
||||
Fortunately there is a simple way to instruct logging changes via boot properties.
|
||||
|
||||
Completely silence console logging by defining its pattern as an empty value.
|
||||
|
||||
[source, yaml]
|
||||
----
|
||||
logging:
|
||||
pattern:
|
||||
console:
|
||||
----
|
||||
|
||||
If you need log from a shell then write those into a file.
|
||||
|
||||
[source, yaml]
|
||||
----
|
||||
logging:
|
||||
file:
|
||||
name: shell.log
|
||||
----
|
||||
|
||||
If you need different log levels.
|
||||
|
||||
[source, yaml]
|
||||
----
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
springframework:
|
||||
shell: debug
|
||||
----
|
||||
|
||||
Passing contiguration properties as command line options is not supported but
|
||||
you can use any other ways supported by boot, for example.
|
||||
|
||||
[source, bash]
|
||||
----
|
||||
$ java -Dlogging.level.root=debug -jar demo.jar
|
||||
$ LOGGING_LEVEL_ROOT=debug java -jar demo.jar
|
||||
----
|
||||
|
||||
NOTE: In a GraalVM image settings are locked during compilation which means
|
||||
you can't change log levels at runtime.
|
||||
@@ -0,0 +1,23 @@
|
||||
[[using-shell-customization-singlecommand]]
|
||||
= Single Command
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
|
||||
|
||||
If your shell application is made for exactly a single purpose having only one
|
||||
command it may be beneficial to configure it for this. Property
|
||||
`spring.shell.noninteractive.primary-command` if defined will disable all other
|
||||
runners than `NonInteractiveShellRunner` and configures it to use
|
||||
defined _Primary Command_.
|
||||
|
||||
[source, yaml]
|
||||
----
|
||||
spring:
|
||||
shell:
|
||||
noninteractive:
|
||||
primary-command: mycommand
|
||||
----
|
||||
|
||||
For example if you have a command `mycommand` with option `arg`
|
||||
it had to be executed with `<shellapp> mycommand --arg hi`, but with above
|
||||
setting it can be executed with `<shellapp> --arg hi`.
|
||||
@@ -0,0 +1,59 @@
|
||||
[[theming]]
|
||||
= Theming
|
||||
|
||||
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
|
||||
|
||||
Current terminal implementations are rich in features and can usually show
|
||||
something else that just plain text. For example a text can be styled to be
|
||||
_bold_ or have different colors. It's also common for terminals to be able
|
||||
to show various characters from an unicode table like emoji's which are usually
|
||||
used to make shell output more pretty.
|
||||
|
||||
Spring Shell supports these via it's theming framework which contains two parts,
|
||||
firstly _styling_ can be used to change text type and secondly _figures_ how
|
||||
some characters are shown. These two are then combined together as a _theme_.
|
||||
|
||||
More about _theming_ internals, see xref:appendices-techical-intro-theming.adoc[Theming].
|
||||
|
||||
NOTE: Default theme is named `default` but can be change using property
|
||||
`spring.shell.theme.name`. Other built-in theme named `dump` uses
|
||||
no styling for colors and tries to not use any special figures.
|
||||
|
||||
Modify existing style by overriding settings.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/ThemingSnippets.java[tag=custom-style-class]
|
||||
----
|
||||
|
||||
Modify existing figures by overriding settings.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/ThemingSnippets.java[tag=custom-figure-class]
|
||||
----
|
||||
|
||||
To create a new theme, create a `ThemeSettings` and provide your own _style_
|
||||
and _figure_ implementations.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/ThemingSnippets.java[tag=custom-theme-class]
|
||||
----
|
||||
|
||||
Register a new bean `Theme` where you can return your custom `ThemeSettings`
|
||||
and a _theme_ name.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/ThemingSnippets.java[tag=custom-theme-config]
|
||||
----
|
||||
|
||||
You can use `ThemeResolver` to resolve _styles_ if you want to create
|
||||
JLine-styled strings programmatically and _figures_ if you want to
|
||||
theme characters for being more pretty.
|
||||
|
||||
[source, java, indent=0]
|
||||
----
|
||||
include::{snippets}/ThemingSnippets.java[tag=using-theme-resolver]
|
||||
----
|
||||
Reference in New Issue
Block a user