Use CommandContext as method parameter

- 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.
- Backport #779
- Fixes #990
This commit is contained in:
Janne Valkealahti
2024-01-24 15:38:22 +00:00
parent 181fb31b2c
commit 65f0b317b7
6 changed files with 137 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
[[writing]]
= Writing
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
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.
@@ -17,9 +17,17 @@ to return anything given `CommandContext` contains reference to
include::{snippets}/WritingSnippets.java[tag=reg-terminal-writer]
----
It's possible to autowire `Terminal` to get access to its 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]
----