此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.0! |
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Shell 3.3.0! |
一个选项要么是必需的,要么不是必需的,一般来说,它的行为方式取决于 命令目标。
使选项成为可选选项。
-
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
) {
}
使选项成为强制性的。
-
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
) {
}