Vincent Demeester 0f9d24f78d
Refactor stack command/package
- Handle `bundlefile` directly in the `top-level`
  command. `bundlefile` is still experimental and will be deprecated
  in future version — this should make be easier to remove it.
- Validate the `stack` name in all cases (i.e. whatever the
  orchestrator is used)
- Load the composefile ahead of choosing the orchestrator. This
  removes some slight duplication.
- Makes `RunDeploy` easier to use from outside packages (like
  `docker/app`) with a preloaded configuration.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-26 14:07:26 +02:00

44 lines
1.2 KiB
Go

package stack
import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/stack/kubernetes"
"github.com/docker/cli/cli/command/stack/options"
"github.com/docker/cli/cli/command/stack/swarm"
"github.com/spf13/cobra"
)
func newRemoveCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command {
var opts options.Remove
cmd := &cobra.Command{
Use: "rm [OPTIONS] STACK [STACK...]",
Aliases: []string{"remove", "down"},
Short: "Remove one or more stacks",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.Namespaces = args
if err := validateStackNames(opts.Namespaces); err != nil {
return err
}
switch {
case common.orchestrator.HasAll():
return errUnsupportedAllOrchestrator
case common.orchestrator.HasKubernetes():
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), common.orchestrator))
if err != nil {
return err
}
return kubernetes.RunRemove(kli, opts)
default:
return swarm.RunRemove(dockerCli, opts)
}
},
}
flags := cmd.Flags()
kubernetes.AddNamespaceFlag(flags)
return cmd
}