Move cli/command/orchestrator to cli/command

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2017-12-04 09:53:03 +01:00 committed by Silvin Lubecki
parent f960d2d5f3
commit 0508c09494
3 changed files with 20 additions and 21 deletions

View File

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

View File

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

View File

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