Browse code

add description in docker plugin ls

Signed-off-by: Victor Vieux <vieux@docker.com>

Victor Vieux authored on 2016/08/10 07:44:54
Showing 5 changed files
... ...
@@ -4,40 +4,58 @@ package plugin
4 4
 
5 5
 import (
6 6
 	"fmt"
7
+	"strings"
7 8
 	"text/tabwriter"
8 9
 
9 10
 	"github.com/docker/docker/api/client"
10 11
 	"github.com/docker/docker/cli"
12
+	"github.com/docker/docker/pkg/stringutils"
11 13
 	"github.com/spf13/cobra"
12 14
 	"golang.org/x/net/context"
13 15
 )
14 16
 
17
+type listOptions struct {
18
+	noTrunc bool
19
+}
20
+
15 21
 func newListCommand(dockerCli *client.DockerCli) *cobra.Command {
22
+	var opts listOptions
23
+
16 24
 	cmd := &cobra.Command{
17 25
 		Use:     "ls",
18 26
 		Short:   "List plugins",
19 27
 		Aliases: []string{"list"},
20 28
 		Args:    cli.NoArgs,
21 29
 		RunE: func(cmd *cobra.Command, args []string) error {
22
-			return runList(dockerCli)
30
+			return runList(dockerCli, opts)
23 31
 		},
24 32
 	}
25 33
 
34
+	flags := cmd.Flags()
35
+
36
+	flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
37
+
26 38
 	return cmd
27 39
 }
28 40
 
29
-func runList(dockerCli *client.DockerCli) error {
41
+func runList(dockerCli *client.DockerCli, opts listOptions) error {
30 42
 	plugins, err := dockerCli.Client().PluginList(context.Background())
31 43
 	if err != nil {
32 44
 		return err
33 45
 	}
34 46
 
35 47
 	w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
36
-	fmt.Fprintf(w, "NAME \tTAG \tACTIVE")
48
+	fmt.Fprintf(w, "NAME \tTAG \tDESCRIPTION\tACTIVE")
37 49
 	fmt.Fprintf(w, "\n")
38 50
 
39 51
 	for _, p := range plugins {
40
-		fmt.Fprintf(w, "%s\t%s\t%v\n", p.Name, p.Tag, p.Active)
52
+		desc := strings.Replace(p.Manifest.Description, "\n", " ", -1)
53
+		desc = strings.Replace(desc, "\r", " ", -1)
54
+		if !opts.noTrunc && len(desc) > 45 {
55
+			desc = stringutils.Truncate(desc, 42) + "..."
56
+		}
57
+
58
+		fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", p.Name, p.Tag, desc, p.Active)
41 59
 	}
42 60
 	w.Flush()
43 61
 	return nil
... ...
@@ -30,8 +30,8 @@ and active:
30 30
 ```bash
31 31
 $ docker plugin ls
32 32
 
33
-NAME                        TAG           ACTIVE
34
-tiborvass/no-remove         latest        true
33
+NAME                  TAG                 DESCRIPTION                ACTIVE
34
+tiborvass/no-remove   latest              A test plugin for Docker   true
35 35
 ```
36 36
 
37 37
 To disable the plugin, use the following command:
... ...
@@ -47,8 +47,8 @@ After the plugin is disabled, it appears as "inactive" in the list of plugins:
47 47
 ```bash
48 48
 $ docker plugin ls
49 49
 
50
-NAME                    VERSION           ACTIVE
51
-tiborvass/no-remove     latest            false
50
+NAME                  TAG                 DESCRIPTION                ACTIVE
51
+tiborvass/no-remove   latest              A test plugin for Docker   false
52 52
 ```
53 53
 
54 54
 ## Related information
... ...
@@ -30,8 +30,8 @@ but disabled ("inactive"):
30 30
 ```bash
31 31
 $ docker plugin ls
32 32
 
33
-NAME                    VERSION             ACTIVE
34
-tiborvass/no-remove     latest              false
33
+NAME                  TAG                 DESCRIPTION                ACTIVE
34
+tiborvass/no-remove   latest              A test plugin for Docker   false
35 35
 ```
36 36
 
37 37
 To enable the plugin, use the following command:
... ...
@@ -47,8 +47,8 @@ After the plugin is enabled, it appears as "active" in the list of plugins:
47 47
 ```bash
48 48
 $ docker plugin ls
49 49
 
50
-NAME                    VERSION             ACTIVE
51
-tiborvass/no-remove     latest              true
50
+NAME                  TAG                 DESCRIPTION                ACTIVE
51
+tiborvass/no-remove   latest              A test plugin for Docker   true
52 52
 ```
53 53
 
54 54
 ## Related information
... ...
@@ -47,8 +47,8 @@ After the plugin is installed, it appears in the list of plugins:
47 47
 ```bash
48 48
 $ docker plugin ls
49 49
 
50
-NAME                  VERSION             ACTIVE
51
-tiborvass/no-remove   latest              true
50
+NAME                  TAG                 DESCRIPTION                ACTIVE
51
+tiborvass/no-remove   latest              A test plugin for Docker   true
52 52
 ```
53 53
 
54 54
 ## Related information
... ...
@@ -20,7 +20,8 @@ Aliases:
20 20
   ls, list
21 21
 
22 22
 Options:
23
-      --help   Print usage
23
+      --help	   Print usage
24
+      --no-trunc   Don't truncate output
24 25
 ```
25 26
 
26 27
 Lists all the plugins that are currently installed. You can install plugins
... ...
@@ -31,8 +32,8 @@ Example output:
31 31
 ```bash
32 32
 $ docker plugin ls
33 33
 
34
-NAME                  VERSION             ACTIVE
35
-tiborvass/no-remove   latest              true
34
+NAME                  TAG                 DESCRIPTION                ACTIVE
35
+tiborvass/no-remove   latest              A test plugin for Docker   true
36 36
 ```
37 37
 
38 38
 ## Related information