1. Writing
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.
CommandRegistration.builder()
.command("example")
.withTarget()
.consumer(ctx -> {
ctx.getTerminal().writer().println("hi");
ctx.getTerminal().writer().flush();
})
.and()
.build();
It’s possible to autowire Terminal to get access to its writer.
@Autowired
Terminal terminal;
@ShellMethod
public void example() {
terminal.writer().println("hi");
terminal.writer().flush();
}