Skip to content

Commit

Permalink
AdditionalHelpMessage set in command annotations, removed env var check
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Tardif <[email protected]>
  • Loading branch information
gtardif committed Dec 2, 2020
1 parent 0ec9e43 commit d7697f9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
cobra.AddTemplateFunc("invalidPluginReason", invalidPluginReason)
cobra.AddTemplateFunc("isPlugin", isPlugin)
cobra.AddTemplateFunc("isExperimental", isExperimental)
cobra.AddTemplateFunc("displayHelpLink", displayHelpLink)
cobra.AddTemplateFunc("cyan", cyan)
cobra.AddTemplateFunc("hasAdditionalHelp", hasAdditionalHelp)
cobra.AddTemplateFunc("additionalHelp", additionalHelp)
cobra.AddTemplateFunc("decoratedName", decoratedName)

rootCmd.SetUsageTemplate(usageTemplate)
Expand All @@ -49,6 +49,8 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
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
}

Expand Down Expand Up @@ -206,12 +208,18 @@ func isExperimental(cmd *cobra.Command) bool {
return experimental
}

func displayHelpLink(cmd *cobra.Command) bool {
hideGuides := os.Getenv("DOCKER_HIDE_HELP_GUIDES") != ""
return !cmd.HasParent() && !hideGuides
func additionalHelp(cmd *cobra.Command) string {
if additionalHelp, ok := cmd.Annotations["additionalHelp"]; ok {
return additionalHelp
}
return ""
}

func hasAdditionalHelp(cmd *cobra.Command) bool {
return additionalHelp(cmd) != ""
}

var cyan = color("\033[1;36m%s\033[0m")
var brightCyan = color("\033[1;96m%s\033[0m")

func color(colorString string) func(...interface{}) string {
sprint := func(args ...interface{}) string {
Expand Down Expand Up @@ -376,8 +384,8 @@ Invalid Plugins:
Run '{{.CommandPath}} COMMAND --help' for more information on a command.
{{- end}}
{{- if displayHelpLink .}}
{{ cyan "To get more help with docker, check out guides at https://docs.docker.com/go/guides/" }}
{{- if hasAdditionalHelp .}}
{{ additionalHelp . }}
{{- end}}
`

Expand Down

0 comments on commit d7697f9

Please sign in to comment.