2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
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 {
|
2016-09-08 13:11:39 -04:00
|
|
|
var errs cli.Errors
|
|
|
|
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 {
|
2016-09-08 13:11:39 -04:00
|
|
|
errs = append(errs, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Fprintln(dockerCli.Out(), name)
|
|
|
|
}
|
|
|
|
// Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
|
|
|
|
if errs != nil {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|