Naming

如果需要修改选项的长名称,可以使用 OptionNameModifier 接口,该接口是一个简单的 Function<String, String>。在这个界面中,输入原始选项名称,然后输出修改后的名称。

If there is a need to modify option long names that can be done using OptionNameModifier interface which is a simple Function<String, String>. In this interface original option name goes in and modified name comes out.

可以在 CommandRegistration 中为每个 OptionSpec 定义修饰符,默认情况下可以作为 bean 或通过配置属性进行全局定义。在 OptionSpec 中手动定义的修饰符优先于全局定义的修饰符。默认情况下没有定义全局修饰符。

Modifier can be defined per OptionSpec in CommandRegistration, defaulting globally as bean or via configuration properties. Modifier defined manually in OptionSpec takes takes precedence over one defined globally. There is no global modifier defined on default.

您可以在 CommandRegistration 中使用一个选项来定义一个修饰符。

You can define one with an option in CommandRegistration.

Unresolved include directive in modules/ROOT/pages/options/naming.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]

将一个 singleton bean 添加为类型 OptionNameModifier,即成为全局默认值。

Add one singleton bean as type OptionNameModifier and that becomes a global default.

Unresolved include directive in modules/ROOT/pages/options/naming.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]

还可以使用 spring.shell.option.naming.case-type 仅添加配置属性,它会根据已定义的类型自动配置一个。

It’s also possible to just add configuration property with spring.shell.option.naming.case-type which auto-configures one based on a type defined.

noop 不执行任何操作,camelsnakekebabpascal 分别激活 camelCasesnake_casekebab-casePascalCase 的内置修饰符。

noop is to do nothing, camel, snake, kebab, pascal activates build-in modifiers for camelCase, snake_case, kebab-case or PascalCase respectively.

如果直接创建 CommandRegistration bean,则仅在使用预配置的 Builder 实例时,全局默认值通过配置属性才能起作用。请参阅更多内容 [using-shell-commands-programmaticmodel]

If creating CommandRegistration beans directly, global default via configuration properies only work if using pre-configured Builder instance. See more [using-shell-commands-programmaticmodel].

spring:
  shell:
     option:
       naming:
         case-type: noop
         # case-type: camel
         # case-type: snake
         # case-type: kebab
         # case-type: pascal

例如,在这种注释方法中定义的选项。

For example options defined in an annotated method like this.

Unresolved include directive in modules/ROOT/pages/options/naming.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]

对于该命令,默认的 help 将显示直接来自 @ShellOption 的名称。

On default help for that command shows names coming directly from @ShellOption.

OPTIONS
       --from_snake String
       [Mandatory]

       --fromCamel String
       [Mandatory]

       --from-kebab String
       [Mandatory]

       --FromPascal String
       [Mandatory]

定义 spring.shell.option.naming.case-type=kebab,然后添加默认修改符,选项名称随后看起来像这样。

Define spring.shell.option.naming.case-type=kebab and default modifier is added and option names then look like.

OPTIONS
       --from-snake String
       [Mandatory]

       --from-camel String
       [Mandatory]

       --from-kebab String
       [Mandatory]

       --from-pascal String
       [Mandatory]