-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
enable.go
48 lines (40 loc) · 1.06 KB
/
enable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package plugin
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
type enableOpts struct {
timeout int
name string
}
func newEnableCommand(dockerCli command.Cli) *cobra.Command {
var opts enableOpts
cmd := &cobra.Command{
Use: "enable [OPTIONS] PLUGIN",
Short: "Enable a plugin",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.name = args[0]
return runEnable(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.IntVar(&opts.timeout, "timeout", 30, "HTTP client timeout (in seconds)")
return cmd
}
func runEnable(dockerCli command.Cli, opts *enableOpts) error {
name := opts.name
if opts.timeout < 0 {
return errors.Errorf("negative timeout %d is invalid", opts.timeout)
}
if err := dockerCli.Client().PluginEnable(context.Background(), name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
return nil
}