github.com/itscaro/cli@v0.0.0-20190705081621-c9db0fe93829/cli/command/plugin/remove.go (about) 1 package plugin 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/docker/cli/cli" 8 "github.com/docker/cli/cli/command" 9 "github.com/docker/docker/api/types" 10 "github.com/spf13/cobra" 11 ) 12 13 type rmOptions struct { 14 force bool 15 16 plugins []string 17 } 18 19 func newRemoveCommand(dockerCli command.Cli) *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.Cli, opts *rmOptions) error { 39 ctx := context.Background() 40 41 var errs cli.Errors 42 for _, name := range opts.plugins { 43 if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil { 44 errs = append(errs, err) 45 continue 46 } 47 fmt.Fprintln(dockerCli.Out(), name) 48 } 49 // Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value. 50 if errs != nil { 51 return errs 52 } 53 return nil 54 }