Display additional help message pointing to docs.docker.com guides.

Will display when user types `docker help` or `docker --help`, but not for `docker run --help`. 

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
Guillame Tardif 2020-12-01 15:04:33 +01:00 committed by Guillaume Tardif
parent 5836f20c28
commit dbd65f92c7
1 changed files with 8 additions and 1 deletions

View File

@ -36,6 +36,7 @@ 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("decoratedName", decoratedName) cobra.AddTemplateFunc("decoratedName", decoratedName)
rootCmd.SetUsageTemplate(usageTemplate) rootCmd.SetUsageTemplate(usageTemplate)
@ -185,7 +186,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 +205,10 @@ func isExperimental(cmd *cobra.Command) bool {
return experimental return experimental
} }
func displayHelpLink(cmd *cobra.Command) bool {
return !cmd.HasParent()
}
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 +364,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 displayHelpLink .}}
To get more help with docker, check out guides at https://docs.docker.com/go/guides.md
{{- end}}
` `
var helpTemplate = ` var helpTemplate = `