github.com/portworx/docker@v1.12.1/api/client/plugin/remove.go (about) 1 // +build experimental 2 3 package plugin 4 5 import ( 6 "fmt" 7 8 "github.com/docker/docker/api/client" 9 "github.com/docker/docker/cli" 10 "github.com/docker/docker/reference" 11 "github.com/spf13/cobra" 12 "golang.org/x/net/context" 13 ) 14 15 func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command { 16 cmd := &cobra.Command{ 17 Use: "rm PLUGIN", 18 Short: "Remove a plugin", 19 Aliases: []string{"remove"}, 20 Args: cli.ExactArgs(1), 21 RunE: func(cmd *cobra.Command, args []string) error { 22 return runRemove(dockerCli, args) 23 }, 24 } 25 26 return cmd 27 } 28 29 func runRemove(dockerCli *client.DockerCli, names []string) error { 30 var errs cli.Errors 31 for _, name := range names { 32 named, err := reference.ParseNamed(name) // FIXME: validate 33 if err != nil { 34 return err 35 } 36 if reference.IsNameOnly(named) { 37 named = reference.WithDefaultTag(named) 38 } 39 ref, ok := named.(reference.NamedTagged) 40 if !ok { 41 return fmt.Errorf("invalid name: %s", named.String()) 42 } 43 // TODO: pass names to api instead of making multiple api calls 44 if err := dockerCli.Client().PluginRemove(context.Background(), ref.String()); 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 }