This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 4.0.1!spring-doc.cn

Command Context

The CommandContext interface gives you access to the context of the currently running command. It provides access to the parsed command input, command registry, and other useful information.spring-doc.cn

@Command(name = "hello")
public void sayHello(CommandContext commandContext) {
	// use command context to get options, arguments and output writer
}

If you need to read input from the shell, you can get the InputReader from the CommandContext and use it to read input. You can find more details about reading from a shell in the Reading Input section.spring-doc.cn

If you need to print something into a shell, you can get a PrintWriter from the CommandContext and use it to print text. You can find more details about writing into a shell in the Writing Output section.spring-doc.cn