mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
0640a14b4f
Using gomvpkg -from github.com/docker/docker/api/client -to github.com/docker/docker/cli/command -vcs_mv_cmd 'git mv {{.Src}} {{.Dst}}' Signed-off-by: Daniel Nephin <dnephin@docker.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package node
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli/command"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type removeOptions struct {
|
|
force bool
|
|
}
|
|
|
|
func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
opts := removeOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "rm [OPTIONS] NODE [NODE...]",
|
|
Aliases: []string{"remove"},
|
|
Short: "Remove one or more nodes from the swarm",
|
|
Args: cli.RequiresMinArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runRemove(dockerCli, args, opts)
|
|
},
|
|
}
|
|
flags := cmd.Flags()
|
|
flags.BoolVar(&opts.force, "force", false, "Force remove an active node")
|
|
return cmd
|
|
}
|
|
|
|
func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error {
|
|
client := dockerCli.Client()
|
|
ctx := context.Background()
|
|
for _, nodeID := range args {
|
|
err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
|
|
}
|
|
return nil
|
|
}
|