2016-05-16 15:50:55 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 18:54:01 +00:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-11-23 00:23:21 +00:00
|
|
|
"github.com/docker/docker/cli/command/formatter"
|
2016-11-23 12:58:15 +00:00
|
|
|
"github.com/docker/docker/opts"
|
2016-05-16 15:50:55 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-08-09 22:44:54 +00:00
|
|
|
type listOptions struct {
|
2016-11-23 00:23:21 +00:00
|
|
|
quiet bool
|
2016-08-09 22:44:54 +00:00
|
|
|
noTrunc bool
|
2016-11-23 00:23:21 +00:00
|
|
|
format string
|
2016-11-23 12:58:15 +00:00
|
|
|
filter opts.FilterOpt
|
2016-08-09 22:44:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 18:54:01 +00:00
|
|
|
func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-11-23 12:58:15 +00:00
|
|
|
opts := listOptions{filter: opts.NewFilterOpt()}
|
2016-08-09 22:44:54 +00:00
|
|
|
|
2016-05-16 15:50:55 +00:00
|
|
|
cmd := &cobra.Command{
|
2016-08-31 06:18:41 +00:00
|
|
|
Use: "ls [OPTIONS]",
|
2016-05-16 15:50:55 +00:00
|
|
|
Short: "List plugins",
|
|
|
|
Aliases: []string{"list"},
|
2016-07-29 17:41:52 +00:00
|
|
|
Args: cli.NoArgs,
|
2016-05-16 15:50:55 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-08-09 22:44:54 +00:00
|
|
|
return runList(dockerCli, opts)
|
2016-05-16 15:50:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-09 22:44:54 +00:00
|
|
|
flags := cmd.Flags()
|
|
|
|
|
2016-11-23 00:23:21 +00:00
|
|
|
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display plugin IDs")
|
2016-08-09 22:44:54 +00:00
|
|
|
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
|
2016-11-23 00:23:21 +00:00
|
|
|
flags.StringVar(&opts.format, "format", "", "Pretty-print plugins using a Go template")
|
2016-11-23 12:58:15 +00:00
|
|
|
flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'enabled=true')")
|
2016-08-09 22:44:54 +00:00
|
|
|
|
2016-05-16 15:50:55 +00:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 18:54:01 +00:00
|
|
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
2016-11-23 12:58:15 +00:00
|
|
|
plugins, err := dockerCli.Client().PluginList(context.Background(), opts.filter.Value())
|
2016-05-16 15:50:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-11-23 00:23:21 +00:00
|
|
|
format := opts.format
|
|
|
|
if len(format) == 0 {
|
|
|
|
if len(dockerCli.ConfigFile().PluginsFormat) > 0 && !opts.quiet {
|
|
|
|
format = dockerCli.ConfigFile().PluginsFormat
|
|
|
|
} else {
|
|
|
|
format = formatter.TableFormatKey
|
2016-08-09 22:44:54 +00:00
|
|
|
}
|
2016-11-23 00:23:21 +00:00
|
|
|
}
|
2016-08-09 22:44:54 +00:00
|
|
|
|
2016-11-23 00:23:21 +00:00
|
|
|
pluginsCtx := formatter.Context{
|
|
|
|
Output: dockerCli.Out(),
|
|
|
|
Format: formatter.NewPluginFormat(format, opts.quiet),
|
|
|
|
Trunc: !opts.noTrunc,
|
2016-05-16 15:50:55 +00:00
|
|
|
}
|
2016-11-23 00:23:21 +00:00
|
|
|
return formatter.PluginWrite(pluginsCtx, plugins)
|
2016-05-16 15:50:55 +00:00
|
|
|
}
|