This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.0! |
Optional Value
An option is either required or not and, generally speaking, how it behaves depends on a command target.
Making option optional.
-
Programmatic
-
Annotation
-
Legacy Annotation
CommandRegistration optionalOption() {
return CommandRegistration.builder()
.command("optionalOption")
.withOption()
.longNames("arg")
.required(false)
.and()
.build();
}
void optionalOption(
@Option(required = false) String arg
) {
}
void optionalOption(
@ShellOption(defaultValue = ShellOption.NULL) String arg
) {
}
Making option mandatory.
-
Programmatic
-
Annotation
-
Legacy Annotation
CommandRegistration mandatoryOption() {
return CommandRegistration.builder()
.command("optionalOption")
.withOption()
.longNames("arg")
.required()
.and()
.build();
}
void mandatoryOption(
@Option(required = true) String arg
) {
}
void mandatoryOption(
@ShellOption() String arg
) {
}