github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/cli/command/plugin/list.go (about) 1 package plugin 2 3 import ( 4 "github.com/docker/docker/cli" 5 "github.com/docker/docker/cli/command" 6 "github.com/docker/docker/cli/command/formatter" 7 "github.com/docker/docker/opts" 8 "github.com/spf13/cobra" 9 "golang.org/x/net/context" 10 ) 11 12 type listOptions struct { 13 quiet bool 14 noTrunc bool 15 format string 16 filter opts.FilterOpt 17 } 18 19 func newListCommand(dockerCli *command.DockerCli) *cobra.Command { 20 opts := listOptions{filter: opts.NewFilterOpt()} 21 22 cmd := &cobra.Command{ 23 Use: "ls [OPTIONS]", 24 Short: "List plugins", 25 Aliases: []string{"list"}, 26 Args: cli.NoArgs, 27 RunE: func(cmd *cobra.Command, args []string) error { 28 return runList(dockerCli, opts) 29 }, 30 } 31 32 flags := cmd.Flags() 33 34 flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display plugin IDs") 35 flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") 36 flags.StringVar(&opts.format, "format", "", "Pretty-print plugins using a Go template") 37 flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'enabled=true')") 38 39 return cmd 40 } 41 42 func runList(dockerCli *command.DockerCli, opts listOptions) error { 43 plugins, err := dockerCli.Client().PluginList(context.Background(), opts.filter.Value()) 44 if err != nil { 45 return err 46 } 47 48 format := opts.format 49 if len(format) == 0 { 50 if len(dockerCli.ConfigFile().PluginsFormat) > 0 && !opts.quiet { 51 format = dockerCli.ConfigFile().PluginsFormat 52 } else { 53 format = formatter.TableFormatKey 54 } 55 } 56 57 pluginsCtx := formatter.Context{ 58 Output: dockerCli.Out(), 59 Format: formatter.NewPluginFormat(format, opts.quiet), 60 Trunc: !opts.noTrunc, 61 } 62 return formatter.PluginWrite(pluginsCtx, plugins) 63 }