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.

By default, commands are grouped into the Default group. However, you can override the group for a command in the following ways, in order of priority:

  1. Specify a group() in the @Command annotation on the method.

  2. Specify a group() in the @Command annotation on the class in which the command is defined. This applies the group for all commands defined in that class (unless overridden, as explained earlier).

The following listing shows an example:

@Command
public class UserCommands {
    @Command(description = "This command ends up in the 'Default' group")
    public void foo() {}

    @Command(description = "This command ends up in the 'Other Commands' group",
    	group = "Other Commands")
    public void bar() {}
}

...

@Command(group = "Other Commands")
public class SomeCommands {
	@Command(description = "This one is in 'Other Commands'")
	public void wizz() {}

	@Command(description = "And this one is 'Yet Another Group'",
		group = "Yet Another Group")
	public void last() {}
}