Merge pull request #2857 from gtardif/help_guides_link

Help guides link
This commit is contained in:
Tibor Vass 2020-12-07 15:34:45 -08:00 committed by GitHub
commit 029ab0255a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 1 deletions

View File

@ -36,6 +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("hasAdditionalHelp", hasAdditionalHelp)
cobra.AddTemplateFunc("additionalHelp", additionalHelp)
cobra.AddTemplateFunc("decoratedName", decoratedName) cobra.AddTemplateFunc("decoratedName", decoratedName)
rootCmd.SetUsageTemplate(usageTemplate) rootCmd.SetUsageTemplate(usageTemplate)
@ -47,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
} }
@ -185,7 +189,6 @@ var helpCommand = &cobra.Command{
if cmd == nil || e != nil || len(args) > 0 { if cmd == nil || e != nil || len(args) > 0 {
return errors.Errorf("unknown help topic: %v", strings.Join(args, " ")) return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
} }
helpFunc := cmd.HelpFunc() helpFunc := cmd.HelpFunc()
helpFunc(cmd, args) helpFunc(cmd, args)
return nil return nil
@ -205,6 +208,27 @@ func isExperimental(cmd *cobra.Command) bool {
return experimental return experimental
} }
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 brightCyan = color("\033[1;96m%s\033[0m")
func color(colorString string) func(...interface{}) string {
sprint := func(args ...interface{}) string {
return fmt.Sprintf(colorString,
fmt.Sprint(args...))
}
return sprint
}
func isPlugin(cmd *cobra.Command) bool { func isPlugin(cmd *cobra.Command) bool {
return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true"
} }
@ -360,6 +384,9 @@ 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 hasAdditionalHelp .}}
{{ additionalHelp . }}
{{- end}}
` `
var helpTemplate = ` var helpTemplate = `