This replaces the visitAll recursive function with a test that verifies that the option is set for all commands and subcommands, so that it doesn't have to be modified at runtime. We currently still have to loop over all functions for the setValidateArgs call, but that can be looked at separately. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package stack
|
|
|
|
import (
|
|
"github.com/docker/cli/cli"
|
|
"github.com/docker/cli/cli/command"
|
|
"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) *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
|
|
}
|
|
return swarm.RunRemove(cmd.Context(), dockerCLI, opts)
|
|
},
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
return completeNames(dockerCLI)(cmd, args, toComplete)
|
|
},
|
|
DisableFlagsInUseLine: true,
|
|
}
|
|
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&opts.Detach, "detach", "d", true, "Do not wait for stack removal")
|
|
return cmd
|
|
}
|