remove.go 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. package node
  2. import (
  3. "fmt"
  4. "golang.org/x/net/context"
  5. "github.com/docker/docker/api/client"
  6. "github.com/docker/docker/cli"
  7. "github.com/spf13/cobra"
  8. )
  9. func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
  10. return &cobra.Command{
  11. Use: "rm NODE [NODE...]",
  12. Aliases: []string{"remove"},
  13. Short: "Remove a node from the swarm",
  14. Args: cli.RequiresMinArgs(1),
  15. RunE: func(cmd *cobra.Command, args []string) error {
  16. return runRemove(dockerCli, args)
  17. },
  18. }
  19. }
  20. func runRemove(dockerCli *client.DockerCli, args []string) error {
  21. client := dockerCli.Client()
  22. ctx := context.Background()
  23. for _, nodeID := range args {
  24. err := client.NodeRemove(ctx, nodeID)
  25. if err != nil {
  26. return err
  27. }
  28. fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
  29. }
  30. return nil
  31. }