github.com/portworx/docker@v1.12.1/api/client/plugin/enable.go (about)

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