|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.1! |
Programmatic
In the programmatic model, commands can be defined as beans of type Command:
@Bean
Command myCommand() {
return Command.builder().name("mycommand").execute(context -> {
System.out.println("This is my command!");
});
}
You can also use the AbstractCommand class to simplify command definitions:
@Bean
Command myCommand() {
return new AbstractCommand("mycommand", "This is my command") {
@Override
public ExitStatus doExecute(CommandContext commandContext) {
println("This is my command!", commandContext);
return ExitStatus.OK;
}
};
}
AbstractCommand provides some utility methods to simplify command creation like
handling help options (-h and --help) and printing messages to the shell output.