github.com/portworx/docker@v1.12.1/api/client/plugin/list.go (about) 1 // +build experimental 2 3 package plugin 4 5 import ( 6 "fmt" 7 "text/tabwriter" 8 9 "github.com/docker/docker/api/client" 10 "github.com/docker/docker/cli" 11 "github.com/spf13/cobra" 12 "golang.org/x/net/context" 13 ) 14 15 func newListCommand(dockerCli *client.DockerCli) *cobra.Command { 16 cmd := &cobra.Command{ 17 Use: "ls", 18 Short: "List plugins", 19 Aliases: []string{"list"}, 20 Args: cli.NoArgs, 21 RunE: func(cmd *cobra.Command, args []string) error { 22 return runList(dockerCli) 23 }, 24 } 25 26 return cmd 27 } 28 29 func runList(dockerCli *client.DockerCli) error { 30 plugins, err := dockerCli.Client().PluginList(context.Background()) 31 if err != nil { 32 return err 33 } 34 35 w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) 36 fmt.Fprintf(w, "NAME \tTAG \tACTIVE") 37 fmt.Fprintf(w, "\n") 38 39 for _, p := range plugins { 40 fmt.Fprintf(w, "%s\t%s\t%v\n", p.Name, p.Tag, p.Active) 41 } 42 w.Flush() 43 return nil 44 }