From d9c36c2878c56ccac8a866150315a3003d3c8da4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 2 Oct 2020 15:30:52 +0200 Subject: [PATCH] cli: print experimental message in usage output Signed-off-by: Sebastiaan van Stijn --- cli/cobra.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cli/cobra.go b/cli/cobra.go index 93a6f661bd..f6104cb508 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -35,6 +35,7 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p cobra.AddTemplateFunc("vendorAndVersion", vendorAndVersion) cobra.AddTemplateFunc("invalidPluginReason", invalidPluginReason) cobra.AddTemplateFunc("isPlugin", isPlugin) + cobra.AddTemplateFunc("isExperimental", isExperimental) cobra.AddTemplateFunc("decoratedName", decoratedName) rootCmd.SetUsageTemplate(usageTemplate) @@ -191,6 +192,19 @@ var helpCommand = &cobra.Command{ }, } +func isExperimental(cmd *cobra.Command) bool { + if _, ok := cmd.Annotations["experimentalCLI"]; ok { + return true + } + var experimental bool + cmd.VisitParents(func(cmd *cobra.Command) { + if _, ok := cmd.Annotations["experimentalCLI"]; ok { + experimental = true + } + }) + return experimental +} + func isPlugin(cmd *cobra.Command) bool { return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" } @@ -286,7 +300,16 @@ var usageTemplate = `Usage: {{- if .HasSubCommands}} {{ .CommandPath}}{{- if .HasAvailableFlags}} [OPTIONS]{{end}} COMMAND{{end}} {{if ne .Long ""}}{{ .Long | trim }}{{ else }}{{ .Short | trim }}{{end}} +{{- if isExperimental .}} +EXPERIMENTAL: + {{.CommandPath}} is an experimental feature. + Experimental features provide early access to product functionality. These + features may change between releases without warning, or can be removed from a + future release. Learn more about experimental features in our documentation: + https://docs.docker.com/go/experimental/ + +{{- end}} {{- if gt .Aliases 0}} Aliases: