disable.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/docker/docker/reference"
  8. "github.com/spf13/cobra"
  9. "golang.org/x/net/context"
  10. )
  11. func newDisableCommand(dockerCli *client.DockerCli) *cobra.Command {
  12. cmd := &cobra.Command{
  13. Use: "disable PLUGIN",
  14. Short: "Disable a plugin",
  15. Args: cli.ExactArgs(1),
  16. RunE: func(cmd *cobra.Command, args []string) error {
  17. return runDisable(dockerCli, args[0])
  18. },
  19. }
  20. return cmd
  21. }
  22. func runDisable(dockerCli *client.DockerCli, name string) error {
  23. named, err := reference.ParseNamed(name) // FIXME: validate
  24. if err != nil {
  25. return err
  26. }
  27. if reference.IsNameOnly(named) {
  28. named = reference.WithDefaultTag(named)
  29. }
  30. ref, ok := named.(reference.NamedTagged)
  31. if !ok {
  32. return fmt.Errorf("invalid name: %s", named.String())
  33. }
  34. if err := dockerCli.Client().PluginDisable(context.Background(), ref.String()); err != nil {
  35. return err
  36. }
  37. fmt.Fprintln(dockerCli.Out(), name)
  38. return nil
  39. }