From e02c28f40a49dd81e6551991c77608921dd8a288 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 22 Jun 2018 11:54:07 -0700 Subject: [PATCH] Remove duplicated getOrchestrator(), and rename hideFlag() Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/cmd.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/cli/command/stack/cmd.go b/cli/command/stack/cmd.go index c9feb99b61..f19b5bfded 100644 --- a/cli/command/stack/cmd.go +++ b/cli/command/stack/cmd.go @@ -7,7 +7,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - cliconfig "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config/configfile" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -32,7 +31,7 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { return err } opts.orchestrator = orchestrator - hideFlag(cmd, orchestrator) + hideOrchestrationFlags(cmd, orchestrator) return checkSupportedFlag(cmd, orchestrator) }, @@ -43,13 +42,7 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { } defaultHelpFunc := cmd.HelpFunc() cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { - config := cliconfig.LoadDefaultConfigFile(dockerCli.Err()) // dockerCli is not yet initialized, but we only need config file here - o, err := getOrchestrator(config, cmd) - if err != nil { - fmt.Fprint(dockerCli.Err(), err) - return - } - hideFlag(cmd, o) + hideOrchestrationFlags(cmd, opts.orchestrator) defaultHelpFunc(cmd, args) }) cmd.AddCommand( @@ -86,7 +79,7 @@ func getOrchestrator(config *configfile.ConfigFile, cmd *cobra.Command) (command return command.GetStackOrchestrator(orchestratorFlag, config.StackOrchestrator) } -func hideFlag(cmd *cobra.Command, orchestrator command.Orchestrator) { +func hideOrchestrationFlags(cmd *cobra.Command, orchestrator command.Orchestrator) { cmd.Flags().VisitAll(func(f *pflag.Flag) { if _, ok := f.Annotations["kubernetes"]; ok && !orchestrator.HasKubernetes() { f.Hidden = true @@ -96,7 +89,7 @@ func hideFlag(cmd *cobra.Command, orchestrator command.Orchestrator) { } }) for _, subcmd := range cmd.Commands() { - hideFlag(subcmd, orchestrator) + hideOrchestrationFlags(subcmd, orchestrator) } }