github.com/kobeld/docker@v1.12.0-rc1/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/spf13/cobra"
    11  	"golang.org/x/net/context"
    12  )
    13  
    14  func newRemoveCommand(dockerCli *client.DockerCli) *cobra.Command {
    15  	cmd := &cobra.Command{
    16  		Use:     "rm",
    17  		Short:   "Remove a plugin",
    18  		Aliases: []string{"remove"},
    19  		Args:    cli.RequiresMinArgs(1),
    20  		RunE: func(cmd *cobra.Command, args []string) error {
    21  			return runRemove(dockerCli, args)
    22  		},
    23  	}
    24  
    25  	return cmd
    26  }
    27  
    28  func runRemove(dockerCli *client.DockerCli, names []string) error {
    29  	var errs cli.Errors
    30  	for _, name := range names {
    31  		// TODO: pass names to api instead of making multiple api calls
    32  		if err := dockerCli.Client().PluginRemove(context.Background(), name); err != nil {
    33  			errs = append(errs, err)
    34  			continue
    35  		}
    36  		fmt.Fprintln(dockerCli.Out(), name)
    37  	}
    38  	// Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
    39  	if errs != nil {
    40  		return errs
    41  	}
    42  	return nil
    43  }