mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	add description in docker plugin ls
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
		
							parent
							
								
									eb28dde01f
								
							
						
					
					
						commit
						16d5fbfd9a
					
				
					 5 changed files with 36 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -4,40 +4,58 @@ package plugin
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"text/tabwriter"
 | 
			
		||||
 | 
			
		||||
	"github.com/docker/docker/api/client"
 | 
			
		||||
	"github.com/docker/docker/cli"
 | 
			
		||||
	"github.com/docker/docker/pkg/stringutils"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
	"golang.org/x/net/context"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type listOptions struct {
 | 
			
		||||
	noTrunc bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newListCommand(dockerCli *client.DockerCli) *cobra.Command {
 | 
			
		||||
	var opts listOptions
 | 
			
		||||
 | 
			
		||||
	cmd := &cobra.Command{
 | 
			
		||||
		Use:     "ls",
 | 
			
		||||
		Short:   "List plugins",
 | 
			
		||||
		Aliases: []string{"list"},
 | 
			
		||||
		Args:    cli.NoArgs,
 | 
			
		||||
		RunE: func(cmd *cobra.Command, args []string) error {
 | 
			
		||||
			return runList(dockerCli)
 | 
			
		||||
			return runList(dockerCli, opts)
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	flags := cmd.Flags()
 | 
			
		||||
 | 
			
		||||
	flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
 | 
			
		||||
 | 
			
		||||
	return cmd
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func runList(dockerCli *client.DockerCli) error {
 | 
			
		||||
func runList(dockerCli *client.DockerCli, opts listOptions) error {
 | 
			
		||||
	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 \tACTIVE")
 | 
			
		||||
	fmt.Fprintf(w, "NAME \tTAG \tDESCRIPTION\tACTIVE")
 | 
			
		||||
	fmt.Fprintf(w, "\n")
 | 
			
		||||
 | 
			
		||||
	for _, p := range plugins {
 | 
			
		||||
		fmt.Fprintf(w, "%s\t%s\t%v\n", p.Name, p.Tag, p.Active)
 | 
			
		||||
		desc := strings.Replace(p.Manifest.Description, "\n", " ", -1)
 | 
			
		||||
		desc = strings.Replace(desc, "\r", " ", -1)
 | 
			
		||||
		if !opts.noTrunc && len(desc) > 45 {
 | 
			
		||||
			desc = stringutils.Truncate(desc, 42) + "..."
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", p.Name, p.Tag, desc, p.Active)
 | 
			
		||||
	}
 | 
			
		||||
	w.Flush()
 | 
			
		||||
	return nil
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,8 +30,8 @@ and active:
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                        TAG           ACTIVE
 | 
			
		||||
tiborvass/no-remove         latest        true
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   true
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                    VERSION           ACTIVE
 | 
			
		||||
tiborvass/no-remove     latest            false
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   false
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Related information
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,8 +30,8 @@ but disabled ("inactive"):
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                    VERSION             ACTIVE
 | 
			
		||||
tiborvass/no-remove     latest              false
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   false
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                    VERSION             ACTIVE
 | 
			
		||||
tiborvass/no-remove     latest              true
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   true
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Related information
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,8 +47,8 @@ After the plugin is installed, it appears in the list of plugins:
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                  VERSION             ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              true
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   true
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Related information
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,8 @@ Aliases:
 | 
			
		|||
  ls, list
 | 
			
		||||
 | 
			
		||||
Options:
 | 
			
		||||
      --help   Print usage
 | 
			
		||||
      --help	   Print usage
 | 
			
		||||
      --no-trunc   Don't truncate output
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Lists all the plugins that are currently installed. You can install plugins
 | 
			
		||||
| 
						 | 
				
			
			@ -31,8 +32,8 @@ Example output:
 | 
			
		|||
```bash
 | 
			
		||||
$ docker plugin ls
 | 
			
		||||
 | 
			
		||||
NAME                  VERSION             ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              true
 | 
			
		||||
NAME                  TAG                 DESCRIPTION                ACTIVE
 | 
			
		||||
tiborvass/no-remove   latest              A test plugin for Docker   true
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Related information
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue