github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/cli/command/plugin/disable.go (about)

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