Browse code

Add `ID` field for `docker plugin ls`

This fix tries to address the enhancement proposed in 28708 to display
ID field for the output of `docker plugin ls`.

This fix add `ID` field to the output of `docker plugin ls`

Related docs has been updated.

This fix fixes 28708.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
(cherry picked from commit 8a226ed6432a0614b25298fef872c98794f65ba9)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Yong Tang authored on 2016/12/03 06:42:50
Showing 2 changed files
... ...
@@ -7,6 +7,7 @@ import (
7 7
 
8 8
 	"github.com/docker/docker/cli"
9 9
 	"github.com/docker/docker/cli/command"
10
+	"github.com/docker/docker/pkg/stringid"
10 11
 	"github.com/docker/docker/pkg/stringutils"
11 12
 	"github.com/spf13/cobra"
12 13
 	"golang.org/x/net/context"
... ...
@@ -43,17 +44,19 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
43 43
 	}
44 44
 
45 45
 	w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0)
46
-	fmt.Fprintf(w, "NAME \tTAG \tDESCRIPTION\tENABLED")
46
+	fmt.Fprintf(w, "ID \tNAME \tTAG \tDESCRIPTION\tENABLED")
47 47
 	fmt.Fprintf(w, "\n")
48 48
 
49 49
 	for _, p := range plugins {
50
+		id := p.ID
50 51
 		desc := strings.Replace(p.Config.Description, "\n", " ", -1)
51 52
 		desc = strings.Replace(desc, "\r", " ", -1)
52 53
 		if !opts.noTrunc {
54
+			id = stringid.TruncateID(p.ID)
53 55
 			desc = stringutils.Ellipsis(desc, 45)
54 56
 		}
55 57
 
56
-		fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", p.Name, p.Tag, desc, p.Enabled)
58
+		fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%v\n", id, p.Name, p.Tag, desc, p.Enabled)
57 59
 	}
58 60
 	w.Flush()
59 61
 	return nil
... ...
@@ -36,8 +36,8 @@ Example output:
36 36
 ```bash
37 37
 $ docker plugin ls
38 38
 
39
-NAME                  TAG                 DESCRIPTION                ENABLED
40
-tiborvass/no-remove   latest              A test plugin for Docker   true
39
+ID                  NAME                  TAG                 DESCRIPTION                ENABLED
40
+69553ca1d123        tiborvass/no-remove   latest              A test plugin for Docker   true
41 41
 ```
42 42
 
43 43
 ## Related information