2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2016-11-21 12:24:01 -05:00
|
|
|
"github.com/docker/docker/api/types"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-11-21 12:24:01 -05:00
|
|
|
type enableOpts struct {
|
|
|
|
timeout int
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:18:27 -04:00
|
|
|
func newEnableCommand(dockerCli command.Cli) *cobra.Command {
|
2016-11-21 12:24:01 -05:00
|
|
|
var opts enableOpts
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
cmd := &cobra.Command{
|
2016-11-24 15:07:06 -05:00
|
|
|
Use: "enable [OPTIONS] PLUGIN",
|
2016-09-08 13:11:39 -04:00
|
|
|
Short: "Enable a plugin",
|
|
|
|
Args: cli.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-11-21 12:24:01 -05:00
|
|
|
opts.name = args[0]
|
|
|
|
return runEnable(dockerCli, &opts)
|
2016-09-08 13:11:39 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-21 12:24:01 -05:00
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.IntVar(&opts.timeout, "timeout", 0, "HTTP client timeout (in seconds)")
|
2016-09-08 13:11:39 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:18:27 -04:00
|
|
|
func runEnable(dockerCli command.Cli, opts *enableOpts) error {
|
2016-11-21 12:24:01 -05:00
|
|
|
name := opts.name
|
|
|
|
if opts.timeout < 0 {
|
2017-03-09 13:23:45 -05:00
|
|
|
return errors.Errorf("negative timeout %d is invalid", opts.timeout)
|
2016-11-21 12:24:01 -05:00
|
|
|
}
|
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
if err := dockerCli.Client().PluginEnable(context.Background(), name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil {
|
2016-09-08 13:11:39 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Fprintln(dockerCli.Out(), name)
|
|
|
|
return nil
|
|
|
|
}
|