From dbd65f92c78e8c29a617d3fc9c9e75d5a15eb581 Mon Sep 17 00:00:00 2001 From: Guillame Tardif Date: Tue, 1 Dec 2020 15:04:33 +0100 Subject: [PATCH 1/4] 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 --- cli/cobra.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/cobra.go b/cli/cobra.go index e118d633bd..b1ae6b59de 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -36,6 +36,7 @@ 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("decoratedName", decoratedName) rootCmd.SetUsageTemplate(usageTemplate) @@ -185,7 +186,6 @@ var helpCommand = &cobra.Command{ if cmd == nil || e != nil || len(args) > 0 { return errors.Errorf("unknown help topic: %v", strings.Join(args, " ")) } - helpFunc := cmd.HelpFunc() helpFunc(cmd, args) return nil @@ -205,6 +205,10 @@ func isExperimental(cmd *cobra.Command) bool { return experimental } +func displayHelpLink(cmd *cobra.Command) bool { + return !cmd.HasParent() +} + func isPlugin(cmd *cobra.Command) bool { return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" } @@ -360,6 +364,9 @@ Invalid Plugins: Run '{{.CommandPath}} COMMAND --help' for more information on a command. {{- end}} +{{- if displayHelpLink .}} +To get more help with docker, check out guides at https://docs.docker.com/go/guides.md +{{- end}} ` var helpTemplate = ` From 2369d9d126de893f10573c001217f89428004a77 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 1 Dec 2020 15:12:09 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Do=20not=20display=20help=20link=20if=20env?= =?UTF-8?q?=20var=20=E2=80=9CDOCKER=5FHIDE=5FHELP=5FGUIDES=E2=80=9D=20is?= =?UTF-8?q?=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guillaume Tardif --- cli/cobra.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/cobra.go b/cli/cobra.go index b1ae6b59de..d6eb3a0c33 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -206,7 +206,8 @@ func isExperimental(cmd *cobra.Command) bool { } func displayHelpLink(cmd *cobra.Command) bool { - return !cmd.HasParent() + hideGuides := os.Getenv("DOCKER_HIDE_HELP_GUIDES") != "" + return !cmd.HasParent() && !hideGuides } func isPlugin(cmd *cobra.Command) bool { @@ -365,7 +366,7 @@ Invalid Plugins: Run '{{.CommandPath}} COMMAND --help' for more information on a command. {{- end}} {{- if displayHelpLink .}} -To get more help with docker, check out guides at https://docs.docker.com/go/guides.md +To get more help with docker, check out guides at https://docs.docker.com/go/guides/ {{- end}} ` From 0ec9e434ed6a75bb54b282c0b3572f3554aefe48 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 1 Dec 2020 17:32:08 +0100 Subject: [PATCH 3/4] Additional help message is displayed in cyan Signed-off-by: Guillaume Tardif --- cli/cobra.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/cobra.go b/cli/cobra.go index d6eb3a0c33..da7fc3425a 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -37,6 +37,7 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p cobra.AddTemplateFunc("isPlugin", isPlugin) cobra.AddTemplateFunc("isExperimental", isExperimental) cobra.AddTemplateFunc("displayHelpLink", displayHelpLink) + cobra.AddTemplateFunc("cyan", cyan) cobra.AddTemplateFunc("decoratedName", decoratedName) rootCmd.SetUsageTemplate(usageTemplate) @@ -210,6 +211,16 @@ func displayHelpLink(cmd *cobra.Command) bool { return !cmd.HasParent() && !hideGuides } +var cyan = color("\033[1;36m%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 { return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" } @@ -366,7 +377,7 @@ Invalid Plugins: Run '{{.CommandPath}} COMMAND --help' for more information on a command. {{- end}} {{- if displayHelpLink .}} -To get more help with docker, check out guides at https://docs.docker.com/go/guides/ +{{ cyan "To get more help with docker, check out guides at https://docs.docker.com/go/guides/" }} {{- end}} ` From d7697f9c722db8e30052d00483ff70e35f2863e8 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 2 Dec 2020 09:56:22 +0100 Subject: [PATCH 4/4] AdditionalHelpMessage set in command annotations, removed env var check Signed-off-by: Guillaume Tardif --- cli/cobra.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cli/cobra.go b/cli/cobra.go index da7fc3425a..72046003d1 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -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) @@ -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 } @@ -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 "" } -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 { sprint := func(args ...interface{}) string { @@ -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}} `