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