|
对于最新的稳定版本,请使用 Spring Shell 3.4.0! |
命令目录
这CommandCataloginterface 定义命令注册在
一个 shell 应用程序。可以动态注册和取消注册
commands,为可能的用例提供了灵活性 命令
来来去去,具体取决于 shell 的状态。请考虑以下示例:
CommandRegistration registration = CommandRegistration.builder().build();
catalog.register(registration);
命令解析器
您可以实现CommandResolver接口并定义一个 Bean 以动态
解析从命令名称到其CommandRegistration实例。考虑
以下示例:
static class CustomCommandResolver implements CommandResolver {
List<CommandRegistration> registrations = new ArrayList<>();
CustomCommandResolver() {
CommandRegistration resolved = CommandRegistration.builder()
.command("resolve command")
.build();
registrations.add(resolved);
}
@Override
public List<CommandRegistration> resolve() {
return registrations;
}
}
当前CommandResolver是每次解析命令时都会使用它。
因此,如果命令解析调用需要很长时间,我们建议不要使用它,因为它会
使 shell 感觉迟钝。 |
命令目录定制器
您可以使用CommandCatalogCustomizerinterface 自定义CommandCatalog.
它的主要用途是修改目录。此外,在spring-shellauto-configuration,则
interface 用于注册现有的CommandRegistration将 bean 添加到目录中。
请考虑以下示例:
static class CustomCommandCatalogCustomizer implements CommandCatalogCustomizer {
@Override
public void customize(CommandCatalog commandCatalog) {
CommandRegistration registration = CommandRegistration.builder()
.command("resolve command")
.build();
commandCatalog.register(registration);
}
}
您可以创建一个CommandCatalogCustomizer作为 bean,而 Spring Shell 会处理其余部分。