此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.3! |
命令目录
这CommandCatalog
interface 定义命令注册在
一个 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 感觉迟钝。 |
命令目录定制器
您可以使用CommandCatalogCustomizer
interface 自定义CommandCatalog
.
它的主要用途是修改目录。此外,在spring-shell
auto-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 会处理其余部分。