|
该版本仍在开发中,尚未被视为稳定。最新稳定版本请使用Spring Shell 3.4.1! |
写作
当需要写入控制台时,你总可以使用 JDKSystem.out然后直接进入JDK自己的流。另一种推荐方式是使用 JLine 的终端然后从那里获取Writer Instance。
如果使用目标端点,即消费者,且不被期望返回返回给定的任何命令上下文包含对终端作者可以从那里访问。
CommandRegistration.builder()
.command("example")
.withTarget()
.consumer(ctx -> {
ctx.getTerminal().writer().println("hi");
ctx.getTerminal().writer().flush();
})
.and()
.build();
如果使用@Command你可以获得访问权限命令上下文并且得到终端从那里开始。
@Command
public void example(CommandContext ctx) {
ctx.getTerminal().writer().println("hi");
ctx.getTerminal().writer().flush();
}
可以自动接线终端以便能够接触到它的作者。
@Autowired
Terminal terminal;
@Command
public void example() {
terminal.writer().println("hi");
terminal.writer().flush();
}