github.com/kunnos/engine@v1.13.1/cli/command/plugin/remove.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/cli" 8 "github.com/docker/docker/cli/command" 9 "github.com/spf13/cobra" 10 "golang.org/x/net/context" 11 ) 12 13 type rmOptions struct { 14 force bool 15 16 plugins []string 17 } 18 19 func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { 20 var opts rmOptions 21 22 cmd := &cobra.Command{ 23 Use: "rm [OPTIONS] PLUGIN [PLUGIN...]", 24 Short: "Remove one or more plugins", 25 Aliases: []string{"remove"}, 26 Args: cli.RequiresMinArgs(1), 27 RunE: func(cmd *cobra.Command, args []string) error { 28 opts.plugins = args 29 return runRemove(dockerCli, &opts) 30 }, 31 } 32 33 flags := cmd.Flags() 34 flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of an active plugin") 35 return cmd 36 } 37 38 func runRemove(dockerCli *command.DockerCli, opts *rmOptions) error { 39 ctx := context.Background() 40 41 var errs cli.Errors 42 for _, name := range opts.plugins { 43 // TODO: pass names to api instead of making multiple api calls 44 if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil { 45 errs = append(errs, err) 46 continue 47 } 48 fmt.Fprintln(dockerCli.Out(), name) 49 } 50 // Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value. 51 if errs != nil { 52 return errs 53 } 54 return nil 55 }