2016-05-16 11:50:55 -04:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-08-09 18:44:54 -04:00
|
|
|
"strings"
|
2016-05-16 11:50:55 -04:00
|
|
|
"text/tabwriter"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 14:54:01 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-08-09 18:44:54 -04:00
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
2016-05-16 11:50:55 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-08-09 18:44:54 -04:00
|
|
|
type listOptions struct {
|
|
|
|
noTrunc bool
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-08-09 18:44:54 -04:00
|
|
|
var opts listOptions
|
|
|
|
|
2016-05-16 11:50:55 -04:00
|
|
|
cmd := &cobra.Command{
|
2016-08-31 02:18:41 -04:00
|
|
|
Use: "ls [OPTIONS]",
|
2016-05-16 11:50:55 -04:00
|
|
|
Short: "List plugins",
|
|
|
|
Aliases: []string{"list"},
|
2016-07-29 13:41:52 -04:00
|
|
|
Args: cli.NoArgs,
|
2016-05-16 11:50:55 -04:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2016-08-09 18:44:54 -04:00
|
|
|
return runList(dockerCli, opts)
|
2016-05-16 11:50:55 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-09 18:44:54 -04:00
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
|
|
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
|
|
|
|
|
2016-05-16 11:50:55 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func runList(dockerCli *command.DockerCli, opts listOptions) error {
|
2016-05-16 11:50:55 -04:00
|
|
|
plugins, err := dockerCli.Client().PluginList(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
|
2016-08-04 19:19:46 -04:00
|
|
|
fmt.Fprintf(w, "NAME \tTAG \tDESCRIPTION\tENABLED")
|
2016-05-16 11:50:55 -04:00
|
|
|
fmt.Fprintf(w, "\n")
|
|
|
|
|
|
|
|
for _, p := range plugins {
|
2016-08-09 18:44:54 -04:00
|
|
|
desc := strings.Replace(p.Manifest.Description, "\n", " ", -1)
|
|
|
|
desc = strings.Replace(desc, "\r", " ", -1)
|
2016-08-10 09:54:14 -04:00
|
|
|
if !opts.noTrunc {
|
|
|
|
desc = stringutils.Ellipsis(desc, 45)
|
2016-08-09 18:44:54 -04:00
|
|
|
}
|
|
|
|
|
2016-08-04 19:19:46 -04:00
|
|
|
fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", p.Name, p.Tag, desc, p.Enabled)
|
2016-05-16 11:50:55 -04:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|