|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.1! |
Organizing Commands
When your shell starts to provide a lot of functionality, you may end up
with a lot of commands, which could be confusing for your users. By typing help,
they would see a daunting list of commands, organized in alphabetical order,
which may not always be the best way to show the available commands.
To alleviate this possible confusion, Spring Shell provides the ability to group commands together,
with reasonable defaults. Related commands would then end up in the same group (for example, User Management Commands)
and be displayed together in the help screen and other places.
Commands can be grouped by specifying a group attribute in the @Command annotation:
@Command(name = "example", group = "My Commands")
public String example() {
return "Hello";
}
The group can also be specified programmatically when using the programmatic registration model
using the Command.Builder.group(String) method:
@Bean
Command myCommand() {
return Command.builder()
.name("mycommand")
.group("My Commands")
.execute(context -> {
System.out.println("This is my command!");
});
}