2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2024-10-19 04:25:50 -04:00
|
|
|
"errors"
|
2016-09-08 13:11:39 -04:00
|
|
|
"fmt"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type rmOptions struct {
|
|
|
|
force bool
|
|
|
|
|
|
|
|
plugins []string
|
|
|
|
}
|
|
|
|
|
2017-10-11 12:18:27 -04:00
|
|
|
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-08 13:11:39 -04:00
|
|
|
var opts rmOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "rm [OPTIONS] PLUGIN [PLUGIN...]",
|
|
|
|
Short: "Remove one or more plugins",
|
|
|
|
Aliases: []string{"remove"},
|
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.plugins = args
|
2023-09-09 18:27:44 -04:00
|
|
|
return runRemove(cmd.Context(), dockerCli, &opts)
|
2016-09-08 13:11:39 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of an active plugin")
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-09-09 18:27:44 -04:00
|
|
|
func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
|
2024-10-19 04:25:50 -04:00
|
|
|
var errs error
|
2016-09-08 13:11:39 -04:00
|
|
|
for _, name := range opts.plugins {
|
2016-12-12 18:05:53 -05:00
|
|
|
if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil {
|
2024-10-19 04:25:50 -04:00
|
|
|
errs = errors.Join(errs, err)
|
2016-09-08 13:11:39 -04:00
|
|
|
continue
|
|
|
|
}
|
2024-10-19 04:25:50 -04:00
|
|
|
_, _ = fmt.Fprintln(dockerCli.Out(), name)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
2024-10-19 04:25:50 -04:00
|
|
|
return errs
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|