帮助选项

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
通过编程或注解定义的命令将自动添加帮助选项。使用注解模型,您只能全局关闭功能,而使用编程模型,您可以按命令修改设置。
© . This site is unofficial and not affiliated with VMware.