For the latest stable version, please use Spring Shell 3.4.0! |
Default Value
Having a default value for an option is somewhat related to Optional Value, as there are cases where you may want to know if the user defined an option and change behavior based on a default value:
-
Programmatic
-
Annotation
-
Legacy Annotation
CommandRegistration defaultOption() {
return CommandRegistration.builder()
.command("defaultOption")
.withOption()
.longNames("arg")
.defaultValue("default")
.and()
.build();
}
void defaultOption(
@Option(defaultValue = "default") String arg
) {
}
void defaultOption(
@ShellOption(defaultValue = "default") String arg
) {
}