- With annotation(@Command) model it's now possible to just add CommandContext and it will get resolved and doesn't cause it to appear as an option. - Fixes #779
34 lines
992 B
Plaintext
34 lines
992 B
Plaintext
[[writing]]
|
|
= Writing
|
|
|
|
ifndef::snippets[:snippets: ../../../../src/test/java/org/springframework/shell/docs]
|
|
|
|
When something needs to get written into your console you can always
|
|
use JDK's `System.out` which then goes directly into JDK's own streams.
|
|
Other recommended way is to use JLine's `Terminal` and get _writer_
|
|
instance from there.
|
|
|
|
If using target endpoints, i.e. _consumer_ which is not expected
|
|
to return anything given `CommandContext` contains reference to
|
|
`Terminal` and writer can be accessed from there.
|
|
|
|
[source, java, indent=0]
|
|
----
|
|
include::{snippets}/WritingSnippets.java[tag=reg-terminal-writer]
|
|
----
|
|
|
|
If using `@Command` you can get access to `CommandContext` and get
|
|
`Terminal` from there.
|
|
|
|
[source, java, indent=0]
|
|
----
|
|
include::{snippets}/WritingSnippets.java[tag=anno-terminal-writer]
|
|
----
|
|
|
|
It's possible to autowire `Terminal` to get access to its writer.
|
|
|
|
[source, java, indent=0]
|
|
----
|
|
include::{snippets}/WritingSnippets.java[tag=legacyanno-terminal-writer]
|
|
----
|