remove.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // +build experimental
  2. package plugin
  3. import (
  4. "fmt"
  5. "github.com/docker/docker/api/client"
  6. "github.com/docker/docker/cli"
  7. "github.com/spf13/cobra"
  8. "golang.org/x/net/context"
  9. )
  10. func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
  11. cmd := &cobra.Command{
  12. Use: "rm PLUGIN",
  13. Short: "Remove a plugin",
  14. Aliases: []string{"remove"},
  15. Args: cli.RequiresMinArgs(1),
  16. RunE: func(cmd *cobra.Command, args []string) error {
  17. return runRemove(dockerCli, args)
  18. },
  19. }
  20. return cmd
  21. }
  22. func runRemove(dockerCli *client.DockerCli, names []string) error {
  23. var errs cli.Errors
  24. for _, name := range names {
  25. // TODO: pass names to api instead of making multiple api calls
  26. if err := dockerCli.Client().PluginRemove(context.Background(), name); err != nil {
  27. errs = append(errs, err)
  28. continue
  29. }
  30. fmt.Fprintln(dockerCli.Out(), name)
  31. }
  32. // Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
  33. if errs != nil {
  34. return errs
  35. }
  36. return nil
  37. }