|
@@ -7,26 +7,36 @@ import (
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli"
|
|
|
|
+ "github.com/docker/engine-api/types"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type removeOptions struct {
|
|
|
|
+ force bool
|
|
|
|
+}
|
|
|
|
+
|
|
func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
- return &cobra.Command{
|
|
|
|
- Use: "rm NODE [NODE...]",
|
|
|
|
|
|
+ opts := removeOptions{}
|
|
|
|
+
|
|
|
|
+ cmd := &cobra.Command{
|
|
|
|
+ Use: "rm [OPTIONS] NODE [NODE...]",
|
|
Aliases: []string{"remove"},
|
|
Aliases: []string{"remove"},
|
|
Short: "Remove one or more nodes from the swarm",
|
|
Short: "Remove one or more nodes from the swarm",
|
|
Args: cli.RequiresMinArgs(1),
|
|
Args: cli.RequiresMinArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
- return runRemove(dockerCli, args)
|
|
|
|
|
|
+ return runRemove(dockerCli, args, opts)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
+ flags := cmd.Flags()
|
|
|
|
+ flags.BoolVar(&opts.force, "force", false, "Force remove an active node")
|
|
|
|
+ return cmd
|
|
}
|
|
}
|
|
|
|
|
|
-func runRemove(dockerCli *client.DockerCli, args []string) error {
|
|
|
|
|
|
+func runRemove(dockerCli *client.DockerCli, args []string, opts removeOptions) error {
|
|
client := dockerCli.Client()
|
|
client := dockerCli.Client()
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
for _, nodeID := range args {
|
|
for _, nodeID := range args {
|
|
- err := client.NodeRemove(ctx, nodeID)
|
|
|
|
|
|
+ err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|