该版本仍在开发中,尚未被视为稳定。最新稳定版本请使用Spring Shell 3.4.1spring-doc.cadn.net.cn

组织指挥

当你的壳开始提供大量功能时,你可能会 命令很多,可能会让用户感到困惑。通过打字帮助, 他们会看到一长串按字母顺序排列的命令清单, 这可能并不总是显示可用命令的最佳方式。spring-doc.cadn.net.cn

为了消除这种可能的混淆,Spring Shell 提供了将命令组合在一起的功能, 而且有合理的违约率。相关命令随后会回到同一组(例如,用户管理命令) 并会一起显示在帮助界面和其他地方。spring-doc.cadn.net.cn

默认情况下,命令根据其实现的类别分组, 将 camelCase 类名称分割成独立的单词(例如URLRelatedCommands成为URL相关命令). 这是一个合理的默认选择,因为相关命令通常已经存在于该类中, 因为它们需要使用相同的协作对象。spring-doc.cadn.net.cn

但如果这种行为不适合你,你可以覆盖该组,使用 按优先级顺序进行以下指令:spring-doc.cadn.net.cn

  1. 指定一个组()@ShellMethod注解。spring-doc.cadn.net.cn

  2. 置a@ShellCommandGroup在该命令定义的类别上。这同样适用 该类中定义的所有命令的组(除非被覆盖,如前所述)。spring-doc.cadn.net.cn

  3. 置a@ShellCommandGroup在包裹(通过)package-info.java) 其中定义了命令。这适用于所有定义在 package(除非如前所述在方法或类层级被覆盖)。spring-doc.cadn.net.cn

以下列表展示了一个示例:spring-doc.cadn.net.cn

public class UserCommands {
    @ShellMethod(value = "This command ends up in the 'User Commands' group")
    public void foo() {}

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

...

@ShellCommandGroup("Other Commands")
public class SomeCommands {
	@ShellMethod(value = "This one is in 'Other Commands'")
	public void wizz() {}

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