For the latest stable version, please use Spring Shell 3.3.3!spring-doc.cn

Optional Value

An option is either required or not and, generally speaking, how it behaves depends on a command target.spring-doc.cn

Making option optional.spring-doc.cn

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.spring-doc.cn

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
) {
}