remove.go 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package network
  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 NETWORK [NETWORK...]",
  12. Aliases: []string{"remove"},
  13. Short: "Remove one or more networks",
  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, networks []string) error {
  21. client := dockerCli.Client()
  22. ctx := context.Background()
  23. status := 0
  24. for _, name := range networks {
  25. if err := client.NetworkRemove(ctx, name); err != nil {
  26. fmt.Fprintf(dockerCli.Err(), "%s\n", err)
  27. status = 1
  28. continue
  29. }
  30. fmt.Fprintf(dockerCli.Out(), "%s\n", name)
  31. }
  32. if status != 0 {
  33. return cli.StatusError{StatusCode: status}
  34. }
  35. return nil
  36. }