幫助選項

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.