Files
docker-cli/cli/command/plugin/enable.go
Sebastiaan van Stijn 4f7c07cfc2 update local code for updated modules
Some tests had to be skipped as there's some issues to address, and
some of the result-types cannot be mocked / stubbed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-24 10:28:54 +02:00

44 lines
1.1 KiB
Go

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
}