From 0508c094942bf80847e0f2eb269d275d3bf671be Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 4 Dec 2017 09:53:03 +0100 Subject: [PATCH] Move cli/command/orchestrator to cli/command Signed-off-by: Vincent Demeester --- .../{orchestrator => }/orchestrator.go | 23 +++++++++---------- cli/command/stack/cmd.go | 15 ++++++------ cli/command/system/version.go | 3 +-- 3 files changed, 20 insertions(+), 21 deletions(-) rename cli/command/{orchestrator => }/orchestrator.go (65%) diff --git a/cli/command/orchestrator/orchestrator.go b/cli/command/orchestrator.go similarity index 65% rename from cli/command/orchestrator/orchestrator.go rename to cli/command/orchestrator.go index a5569cd858..7297383201 100644 --- a/cli/command/orchestrator/orchestrator.go +++ b/cli/command/orchestrator.go @@ -1,10 +1,9 @@ -package orchestrator +package command import ( "os" "strings" - "github.com/docker/cli/cli/command" cliconfig "github.com/docker/cli/cli/config" ) @@ -13,37 +12,37 @@ type Orchestrator string const ( // Kubernetes orchestrator - Kubernetes = Orchestrator("kubernetes") + OrchestratorKubernetes = Orchestrator("kubernetes") // Swarm orchestrator - Swarm = Orchestrator("swarm") - unset = Orchestrator("unset") + OrchestratorSwarm = Orchestrator("swarm") + orchestratorUnset = Orchestrator("unset") - defaultOrchestrator = Swarm + defaultOrchestrator = OrchestratorSwarm dockerOrchestrator = "DOCKER_ORCHESTRATOR" ) func normalize(flag string) Orchestrator { switch strings.ToLower(flag) { case "kubernetes", "k8s": - return Kubernetes + return OrchestratorKubernetes case "swarm", "swarmkit": - return Swarm + return OrchestratorSwarm default: - return unset + return orchestratorUnset } } // GetOrchestrator checks DOCKER_ORCHESTRATOR environment variable and configuration file // orchestrator value and returns user defined Orchestrator. -func GetOrchestrator(dockerCli command.Cli) Orchestrator { +func GetOrchestrator(dockerCli Cli) Orchestrator { // Check environment variable env := os.Getenv(dockerOrchestrator) - if o := normalize(env); o != unset { + if o := normalize(env); o != orchestratorUnset { return o } // Check config file if configFile := cliconfig.LoadDefaultConfigFile(dockerCli.Err()); configFile != nil { - if o := normalize(configFile.Orchestrator); o != unset { + if o := normalize(configFile.Orchestrator); o != orchestratorUnset { return o } } diff --git a/cli/command/stack/cmd.go b/cli/command/stack/cmd.go index 442077f90f..a4b9f08141 100644 --- a/cli/command/stack/cmd.go +++ b/cli/command/stack/cmd.go @@ -3,7 +3,6 @@ package stack import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/orchestrator" "github.com/docker/cli/cli/command/stack/kubernetes" "github.com/docker/cli/cli/command/stack/swarm" "github.com/spf13/cobra" @@ -18,10 +17,10 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{"version": "1.25"}, } - switch orchestrator.GetOrchestrator(dockerCli) { - case orchestrator.Kubernetes: + switch command.GetOrchestrator(dockerCli) { + case command.OrchestratorKubernetes: kubernetes.AddStackCommands(cmd, dockerCli) - case orchestrator.Swarm: + case command.OrchestratorSwarm: swarm.AddStackCommands(cmd, dockerCli) } return cmd @@ -30,10 +29,12 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command { // NewTopLevelDeployCommand returns a command for `docker deploy` func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command { var cmd *cobra.Command - switch orchestrator.GetOrchestrator(dockerCli) { - case orchestrator.Kubernetes: + switch command.GetOrchestrator(dockerCli) { + case command.OrchestratorKubernetes: cmd = kubernetes.NewTopLevelDeployCommand(dockerCli) - case orchestrator.Swarm: + case command.OrchestratorSwarm: + cmd = swarm.NewTopLevelDeployCommand(dockerCli) + default: cmd = swarm.NewTopLevelDeployCommand(dockerCli) } // Remove the aliases at the top level diff --git a/cli/command/system/version.go b/cli/command/system/version.go index 40dff7c989..f6a725ae23 100644 --- a/cli/command/system/version.go +++ b/cli/command/system/version.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/command/orchestrator" "github.com/docker/cli/templates" "github.com/docker/docker/api/types" "github.com/spf13/cobra" @@ -139,7 +138,7 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error { Os: runtime.GOOS, Arch: runtime.GOARCH, Experimental: dockerCli.ClientInfo().HasExperimental, - Orchestrator: string(orchestrator.GetOrchestrator(dockerCli)), + Orchestrator: string(command.GetOrchestrator(dockerCli)), }, } vd.Client.Platform.Name = cli.PlatformName