Skip to content

Commit

Permalink
Remove duplicated getOrchestrator(), and rename hideFlag()
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jun 22, 2018
1 parent f0a8598 commit c2c317c
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions cli/command/stack/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
},

Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -96,7 +89,7 @@ func hideFlag(cmd *cobra.Command, orchestrator command.Orchestrator) {
}
})
for _, subcmd := range cmd.Commands() {
hideFlag(subcmd, orchestrator)
hideOrchestrationFlags(subcmd, orchestrator)
}
}

Expand Down

0 comments on commit c2c317c

Please sign in to comment.