命令上下文
The CommandContext 接口为您提供当前运行命令的上下文访问。它提供了对解析后的命令输入、命令注册表以及其他有用信息的访问。
@Command(name = "hello")
public void sayHello(CommandContext commandContext) {
// use command context to get options, arguments and output writer
}
如果需要从终端读取输入,可以获取InputReader从CommandContext并使用它来读取输入。您可以在读取输入部分找到更多关于从终端读取内容的详细信息。
如果您需要将内容打印到控制台,可以从CommandContext获取一个PrintWriter并使用它来打印文本。您可以在输出编写部分找到更多关于向控制台写入的内容。