Remove duplicated getOrchestrator(), and rename hideFlag()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2018-06-22 11:54:07 -07:00
parent 151990de62
commit e02c28f40a
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 4 additions and 11 deletions

View File

@ -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)
}
}