AdditionalHelpMessage set in command annotations, removed env var check

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
Guillaume Tardif 2020-12-02 09:56:22 +01:00
parent 0ec9e434ed
commit d7697f9c72
1 changed files with 16 additions and 8 deletions

View File

@ -36,8 +36,8 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
cobra.AddTemplateFunc("invalidPluginReason", invalidPluginReason) cobra.AddTemplateFunc("invalidPluginReason", invalidPluginReason)
cobra.AddTemplateFunc("isPlugin", isPlugin) cobra.AddTemplateFunc("isPlugin", isPlugin)
cobra.AddTemplateFunc("isExperimental", isExperimental) cobra.AddTemplateFunc("isExperimental", isExperimental)
cobra.AddTemplateFunc("displayHelpLink", displayHelpLink) cobra.AddTemplateFunc("hasAdditionalHelp", hasAdditionalHelp)
cobra.AddTemplateFunc("cyan", cyan) cobra.AddTemplateFunc("additionalHelp", additionalHelp)
cobra.AddTemplateFunc("decoratedName", decoratedName) cobra.AddTemplateFunc("decoratedName", decoratedName)
rootCmd.SetUsageTemplate(usageTemplate) rootCmd.SetUsageTemplate(usageTemplate)
@ -49,6 +49,8 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help") rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
rootCmd.PersistentFlags().Lookup("help").Hidden = true rootCmd.PersistentFlags().Lookup("help").Hidden = true
rootCmd.Annotations = map[string]string{"additionalHelp": brightCyan("To get more help with docker, check out guides at https://docs.docker.com/go/guides/")}
return opts, flags, helpCommand return opts, flags, helpCommand
} }
@ -206,12 +208,18 @@ func isExperimental(cmd *cobra.Command) bool {
return experimental return experimental
} }
func displayHelpLink(cmd *cobra.Command) bool { func additionalHelp(cmd *cobra.Command) string {
hideGuides := os.Getenv("DOCKER_HIDE_HELP_GUIDES") != "" if additionalHelp, ok := cmd.Annotations["additionalHelp"]; ok {
return !cmd.HasParent() && !hideGuides return additionalHelp
}
return ""
} }
var cyan = color("\033[1;36m%s\033[0m") func hasAdditionalHelp(cmd *cobra.Command) bool {
return additionalHelp(cmd) != ""
}
var brightCyan = color("\033[1;96m%s\033[0m")
func color(colorString string) func(...interface{}) string { func color(colorString string) func(...interface{}) string {
sprint := func(args ...interface{}) string { sprint := func(args ...interface{}) string {
@ -376,8 +384,8 @@ Invalid Plugins:
Run '{{.CommandPath}} COMMAND --help' for more information on a command. Run '{{.CommandPath}} COMMAND --help' for more information on a command.
{{- end}} {{- end}}
{{- if displayHelpLink .}} {{- if hasAdditionalHelp .}}
{{ cyan "To get more help with docker, check out guides at https://docs.docker.com/go/guides/" }} {{ additionalHelp . }}
{{- end}} {{- end}}
` `