github.com/kunnos/engine@v1.13.1/cli/command/plugin/enable.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/cli" 8 "github.com/docker/docker/cli/command" 9 "github.com/spf13/cobra" 10 "golang.org/x/net/context" 11 ) 12 13 type enableOpts struct { 14 timeout int 15 name string 16 } 17 18 func newEnableCommand(dockerCli *command.DockerCli) *cobra.Command { 19 var opts enableOpts 20 21 cmd := &cobra.Command{ 22 Use: "enable [OPTIONS] PLUGIN", 23 Short: "Enable a plugin", 24 Args: cli.ExactArgs(1), 25 RunE: func(cmd *cobra.Command, args []string) error { 26 opts.name = args[0] 27 return runEnable(dockerCli, &opts) 28 }, 29 } 30 31 flags := cmd.Flags() 32 flags.IntVar(&opts.timeout, "timeout", 0, "HTTP client timeout (in seconds)") 33 return cmd 34 } 35 36 func runEnable(dockerCli *command.DockerCli, opts *enableOpts) error { 37 name := opts.name 38 if opts.timeout < 0 { 39 return fmt.Errorf("negative timeout %d is invalid", opts.timeout) 40 } 41 42 if err := dockerCli.Client().PluginEnable(context.Background(), name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil { 43 return err 44 } 45 fmt.Fprintln(dockerCli.Out(), name) 46 return nil 47 }