From 9c97d5bc8ad2c626c37b1d369cedd328b4d44b2f Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 8 Nov 2019 15:11:35 +0100 Subject: [PATCH] --installer-context option is experimental Signed-off-by: Nicolas De Loof --- internal/cliopts/installerContext.go | 1 + internal/commands/root.go | 26 ++++++++++++++++---------- internal/commands/validate.go | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/internal/cliopts/installerContext.go b/internal/cliopts/installerContext.go index 73bfd81c5..4eeab2c30 100644 --- a/internal/cliopts/installerContext.go +++ b/internal/cliopts/installerContext.go @@ -22,6 +22,7 @@ func (o *InstallerContextOptions) AddFlags(flags *pflag.FlagSet) { defaultContext = "default" } flags.StringVar(&o.installerContext, "installer-context", defaultContext, "Context on which the installer image is ran") + flags.SetAnnotation("installer-context", "experimentalCLI", []string{"true"}) //nolint:errcheck } func (o *InstallerContextOptions) SetInstallerContext(dockerCli command.Cli) (command.Cli, error) { diff --git a/internal/commands/root.go b/internal/commands/root.go index 4eac33e36..099110e22 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -48,7 +48,7 @@ func NewRootCmd(use string, dockerCli command.Cli) *cobra.Command { } func addCommands(cmd *cobra.Command, dockerCli command.Cli) { - listOfCommands := []*cobra.Command{ + cmd.AddCommand( runCmd(dockerCli), updateCmd(dockerCli), removeCmd(dockerCli), @@ -60,18 +60,24 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) { image.Cmd(dockerCli), build.Cmd(dockerCli), inspectCmd(dockerCli), + ) + + if !dockerCli.ClientInfo().HasExperimental { + hideExperimentalCLI(cmd) } +} - isExperimentalMode := dockerCli.ClientInfo().HasExperimental - for _, ccmd := range listOfCommands { - switch ccmd.Annotations["experimental"] { - case "true": - if isExperimentalMode { - cmd.AddCommand(ccmd) - } - default: - cmd.AddCommand(ccmd) +func hideExperimentalCLI(cmd *cobra.Command) { + if _, ok := cmd.Annotations["experimentalCLI"]; ok { + cmd.Hidden = true + } + cmd.Flags().VisitAll(func(f *pflag.Flag) { + if _, ok := f.Annotations["experimentalCLI"]; ok { + f.Hidden = true } + }) + for _, subcmd := range cmd.Commands() { + hideExperimentalCLI(subcmd) } } diff --git a/internal/commands/validate.go b/internal/commands/validate.go index 1b39de399..e0c10ddcd 100644 --- a/internal/commands/validate.go +++ b/internal/commands/validate.go @@ -26,7 +26,7 @@ func validateCmd() *cobra.Command { Short: "Check that an App definition (.dockerapp) is syntactically correct", Example: `$ docker app validate myapp.dockerapp --set key=value --parameters-file myparam.yml`, Args: cli.RequiresMaxArgs(1), - Annotations: map[string]string{"experimental": "true"}, + Annotations: map[string]string{"experimentalCLI": "true"}, RunE: func(cmd *cobra.Command, args []string) error { return runValidate(args, opts) },