This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.0!

Naming

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.

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.

You can define one with an option in CommandRegistration.

CommandRegistration.builder()
	.withOption()
		.longNames("arg1")
		.nameModifier(name -> "x" + name)
		.and()
	.build();

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

@Bean
OptionNameModifier sampleOptionNameModifier() {
	return name -> "x" + name;
}

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 is to do nothing, camel, snake, kebab, pascal activates build-in modifiers for camelCase, snake_case, kebab-case or PascalCase respectively.

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.

@ShellMethod(key = "option-naming-sample")
public void optionNamingSample(
	@ShellOption("from_snake") String snake,
	@ShellOption("fromCamel") String camel,
	@ShellOption("from-kebab") String kebab,
	@ShellOption("FromPascal") String pascal
) {}

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]

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]