Skip to content

Commit d9c36c2

Browse files
committed
cli: print experimental message in usage output
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 0d11ef3 commit d9c36c2

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

cli/cobra.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
3535
cobra.AddTemplateFunc("vendorAndVersion", vendorAndVersion)
3636
cobra.AddTemplateFunc("invalidPluginReason", invalidPluginReason)
3737
cobra.AddTemplateFunc("isPlugin", isPlugin)
38+
cobra.AddTemplateFunc("isExperimental", isExperimental)
3839
cobra.AddTemplateFunc("decoratedName", decoratedName)
3940

4041
rootCmd.SetUsageTemplate(usageTemplate)
@@ -191,6 +192,19 @@ var helpCommand = &cobra.Command{
191192
},
192193
}
193194

195+
func isExperimental(cmd *cobra.Command) bool {
196+
if _, ok := cmd.Annotations["experimentalCLI"]; ok {
197+
return true
198+
}
199+
var experimental bool
200+
cmd.VisitParents(func(cmd *cobra.Command) {
201+
if _, ok := cmd.Annotations["experimentalCLI"]; ok {
202+
experimental = true
203+
}
204+
})
205+
return experimental
206+
}
207+
194208
func isPlugin(cmd *cobra.Command) bool {
195209
return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true"
196210
}
@@ -286,7 +300,16 @@ var usageTemplate = `Usage:
286300
{{- if .HasSubCommands}} {{ .CommandPath}}{{- if .HasAvailableFlags}} [OPTIONS]{{end}} COMMAND{{end}}
287301
288302
{{if ne .Long ""}}{{ .Long | trim }}{{ else }}{{ .Short | trim }}{{end}}
303+
{{- if isExperimental .}}
304+
305+
EXPERIMENTAL:
306+
{{.CommandPath}} is an experimental feature.
307+
Experimental features provide early access to product functionality. These
308+
features may change between releases without warning, or can be removed from a
309+
future release. Learn more about experimental features in our documentation:
310+
https://docs.docker.com/go/experimental/
289311
312+
{{- end}}
290313
{{- if gt .Aliases 0}}
291314
292315
Aliases:

0 commit comments

Comments
 (0)