disable.go 914 B

123456789101112131415161718192021222324252627282930313233343536
  1. package plugin
  2. import (
  3. "fmt"
  4. "github.com/docker/docker/api/types"
  5. "github.com/docker/docker/cli"
  6. "github.com/docker/docker/cli/command"
  7. "github.com/spf13/cobra"
  8. "golang.org/x/net/context"
  9. )
  10. func newDisableCommand(dockerCli *command.DockerCli) *cobra.Command {
  11. var force bool
  12. cmd := &cobra.Command{
  13. Use: "disable [OPTIONS] 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], force)
  18. },
  19. }
  20. flags := cmd.Flags()
  21. flags.BoolVarP(&force, "force", "f", false, "Force the disable of an active plugin")
  22. return cmd
  23. }
  24. func runDisable(dockerCli *command.DockerCli, name string, force bool) error {
  25. if err := dockerCli.Client().PluginDisable(context.Background(), name, types.PluginDisableOptions{Force: force}); err != nil {
  26. return err
  27. }
  28. fmt.Fprintln(dockerCli.Out(), name)
  29. return nil
  30. }