2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 14:54:01 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type listOptions struct {
|
|
|
|
noTrunc bool
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-09-08 13:11:39 -04:00
|
|
|
var opts listOptions
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
2016-09-08 13:11:39 -04:00
|
|
|
plugins, err := dockerCli.Client().PluginList(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
|
|
|
|
fmt.Fprintf(w, "NAME \tTAG \tDESCRIPTION\tENABLED")
|
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
|
|
|
|
for _, p := range plugins {
|
2016-11-07 21:51:47 -05:00
|
|
|
desc := strings.Replace(p.Config.Description, "\n", " ", -1)
|
2016-09-08 13:11:39 -04:00
|
|
|
desc = strings.Replace(desc, "\r", " ", -1)
|
|
|
|
if !opts.noTrunc {
|
|
|
|
desc = stringutils.Ellipsis(desc, 45)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", p.Name, p.Tag, desc, p.Enabled)
|
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|