Command Catalog
CommandCatalog
接口定义了命令注册在 shell 应用程序中的方式。可以动态地注册和注销命令,这为可能的命令来回使用的用例提供了灵活性,具体取决于 shell 的状态。考虑以下示例:
The CommandCatalog
interface defines how command registrations exist in
a shell application. It is possible to dynamically register and de-register
commands, which gives flexibility for use cases where possible commands
come and go, depending on a shell’s state. Consider the following example:
Unresolved include directive in modules/ROOT/pages/appendices/techintro/commandcatalog.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/CommandCatalogSnippets.java[]
Command Resolver
你可以实现 CommandResolver
接口并定义一个 bean,以动态解析从命令的名称到其 CommandRegistration
实例的映射。考虑以下示例:
You can implement the CommandResolver
interface and define a bean to dynamically
resolve mappings from a command’s name to its CommandRegistration
instances. Consider
the following example:
Unresolved include directive in modules/ROOT/pages/appendices/techintro/commandcatalog.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/CommandCatalogSnippets.java[]
CommandResolver
目前的局限性在于,它会在每次解析命令时被使用。因此,我们建议如果命令解析调用花费时间较长,请不要使用它,因为它会使 shell 感觉迟缓。
A current limitation of a CommandResolver
is that it is used every time commands are resolved.
Thus, we advise not using it if a command resolution call takes a long time, as it would
make the shell feel sluggish.
Command Catalog Customizer
你可以使用 CommandCatalogCustomizer
接口来自定义 CommandCatalog
。它的主要用途是修改目录。此外,在 spring-shell
自动配置中,此接口用于将现有的 CommandRegistration
bean 注册到目录中。考虑以下示例:
You can use the CommandCatalogCustomizer
interface to customize a CommandCatalog
.
Its main use is to modify a catalog. Also, within spring-shell
auto-configuration, this
interface is used to register existing CommandRegistration
beans into a catalog.
Consider the following example:
Unresolved include directive in modules/ROOT/pages/appendices/techintro/commandcatalog.adoc - include::../../../../../src/test/java/org/springframework/shell/docs/CommandCatalogSnippets.java[]
你可以将一个 CommandCatalogCustomizer
创建为 bean,而且 Spring Shell 会处理其余的事情。
You can create a CommandCatalogCustomizer
as a bean, and Spring Shell handles the rest.