-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathenable.go
More file actions
43 lines (37 loc) · 1.09 KB
/
enable.go
File metadata and controls
43 lines (37 loc) · 1.09 KB
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
package plugin
import (
"context"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
func newEnableCommand(dockerCLI command.Cli) *cobra.Command {
var opts client.PluginEnableOptions
cmd := &cobra.Command{
Use: "enable [OPTIONS] PLUGIN",
Short: "Enable a plugin",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
if err := runEnable(cmd.Context(), dockerCLI, name, opts); err != nil {
return err
}
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
return nil
},
ValidArgsFunction: completeNames(dockerCLI, stateDisabled),
DisableFlagsInUseLine: true,
}
flags := cmd.Flags()
flags.IntVar(&opts.Timeout, "timeout", 30, "HTTP client timeout (in seconds)")
return cmd
}
func runEnable(ctx context.Context, dockerCli command.Cli, name string, opts client.PluginEnableOptions) error {
if opts.Timeout < 0 {
return fmt.Errorf("negative timeout %d is invalid", opts.Timeout)
}
_, err := dockerCli.Client().PluginEnable(ctx, name, opts)
return err
}