github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/node/remove.go (about) 1 package node 2 3 import ( 4 "fmt" 5 6 "golang.org/x/net/context" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/cli" 10 "github.com/docker/docker/cli/command" 11 "github.com/spf13/cobra" 12 ) 13 14 type removeOptions struct { 15 force bool 16 } 17 18 func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { 19 opts := removeOptions{} 20 21 cmd := &cobra.Command{ 22 Use: "rm [OPTIONS] NODE [NODE...]", 23 Aliases: []string{"remove"}, 24 Short: "Remove one or more nodes from the swarm", 25 Args: cli.RequiresMinArgs(1), 26 RunE: func(cmd *cobra.Command, args []string) error { 27 return runRemove(dockerCli, args, opts) 28 }, 29 } 30 flags := cmd.Flags() 31 flags.BoolVar(&opts.force, "force", false, "Force remove an active node") 32 return cmd 33 } 34 35 func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error { 36 client := dockerCli.Client() 37 ctx := context.Background() 38 for _, nodeID := range args { 39 err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force}) 40 if err != nil { 41 return err 42 } 43 fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID) 44 } 45 return nil 46 }