github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/stack/remove.go (about)

     1  package stack
     2  
     3  import (
     4  	"github.com/docker/cli/cli"
     5  	"github.com/docker/cli/cli/command"
     6  	"github.com/docker/cli/cli/command/stack/kubernetes"
     7  	"github.com/docker/cli/cli/command/stack/options"
     8  	"github.com/docker/cli/cli/command/stack/swarm"
     9  	"github.com/spf13/cobra"
    10  	"github.com/spf13/pflag"
    11  )
    12  
    13  func newRemoveCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command {
    14  	var opts options.Remove
    15  
    16  	cmd := &cobra.Command{
    17  		Use:     "rm [OPTIONS] STACK [STACK...]",
    18  		Aliases: []string{"remove", "down"},
    19  		Short:   "Remove one or more stacks",
    20  		Args:    cli.RequiresMinArgs(1),
    21  		RunE: func(cmd *cobra.Command, args []string) error {
    22  			opts.Namespaces = args
    23  			if err := validateStackNames(opts.Namespaces); err != nil {
    24  				return err
    25  			}
    26  			return RunRemove(dockerCli, cmd.Flags(), common.Orchestrator(), opts)
    27  		},
    28  	}
    29  	flags := cmd.Flags()
    30  	kubernetes.AddNamespaceFlag(flags)
    31  	return cmd
    32  }
    33  
    34  // RunRemove performs a stack remove against the specified orchestrator
    35  func RunRemove(dockerCli command.Cli, flags *pflag.FlagSet, commonOrchestrator command.Orchestrator, opts options.Remove) error {
    36  	return runOrchestratedCommand(dockerCli, flags, commonOrchestrator,
    37  		func() error { return swarm.RunRemove(dockerCli, opts) },
    38  		func(kli *kubernetes.KubeCli) error { return kubernetes.RunRemove(kli, opts) })
    39  }