帮助选项
Spring Shell 内置了 help
命令,但并非所有人都喜欢使用它来获取命令帮助,因为您始终需要使用目标命令的参数来调用它。在许多 CLI 框架中,每个命令通常都有 --help 和 -h 选项来打印命令帮助。
默认功能是每个命令都会被修改为包含 --help 和 -h 选项,如果在给定命令中存在这些选项,则无论键入的其他命令行选项是什么,都会自动将命令执行短路到现有的 help
命令中。
下面的示例显示了它的默认设置。
@Bean
CommandRegistration commandRegistration() {
return CommandRegistration.builder()
.command("mycommand")
.withHelpOptions()
.enabled(true)
.longNames("help")
.shortNames('h')
.command("help")
.and()
.build();
}
可以通过配置选项更改默认行为。
spring:
shell:
help:
enabled: true
long-names: help
short-names: h
command: help
以编程方式或通过注解定义的命令会自动添加帮助选项。使用注解模型,您只能全局关闭这些选项,编程模型允许您为每个命令修改设置。 |