cli/command/plugin: fix linting issues, and assorted cleanups

- fix various unhandled errors
- remove some locally defined option-types in favor of option-types
  defined by the client / api
- don't use unkeyed structs in tests, and add docs for some subtests
- fix some values in tests that triggered "spellcheck" warnings
- inline vars / functions that only had a single use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-07-26 15:58:06 +02:00
parent 2f87a11e96
commit c6f935eba5
16 changed files with 124 additions and 105 deletions

View File

@ -1,7 +1,6 @@
package plugin
import (
"context"
"fmt"
"github.com/docker/cli/cli"
@ -10,27 +9,24 @@ import (
"github.com/spf13/cobra"
)
func newDisableCommand(dockerCli command.Cli) *cobra.Command {
var force bool
func newDisableCommand(dockerCLI command.Cli) *cobra.Command {
var opts types.PluginDisableOptions
cmd := &cobra.Command{
Use: "disable [OPTIONS] PLUGIN",
Short: "Disable a plugin",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runDisable(cmd.Context(), dockerCli, args[0], force)
name := args[0]
if err := dockerCLI.Client().PluginDisable(cmd.Context(), name, opts); err != nil {
return err
}
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
return nil
},
}
flags := cmd.Flags()
flags.BoolVarP(&force, "force", "f", false, "Force the disable of an active plugin")
flags.BoolVarP(&opts.Force, "force", "f", false, "Force the disable of an active plugin")
return cmd
}
func runDisable(ctx context.Context, dockerCli command.Cli, name string, force bool) error {
if err := dockerCli.Client().PluginDisable(ctx, name, types.PluginDisableOptions{Force: force}); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
return nil
}