Add `--format` flag for `docker plugin ls`

This fix tries to address the enhancement discussed in 28735 to add
`--format` for the output of `docker plugin ls`.

This fix
1. Add `--format` and `--quiet` flags to `docker plugin ls`
2. Convert the current implementation to use `formatter`, consistent with
   other docker list commands.
3. Add `pluginsFormat` for config.json.

Related docs has been updated.

Several unit tests have been added to cover the changes.

This fix is related to 28708 and 28735.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
master
Yong Tang 2016-11-22 16:23:21 -08:00 committed by Tibor Vass
parent e65d4d2907
commit d36dd6541a
2 changed files with 37 additions and 2 deletions

View File

@ -131,6 +131,12 @@ Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
directives, see the [**Formatting** section in the `docker images` documentation](images.md)
The property `pluginsFormat` specifies the default format for `docker plugin ls` output.
When the `--format` flag is not provided with the `docker plugin ls` command,
Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
directives, see the [**Formatting** section in the `docker plugin ls` documentation](plugin_ls.md)
The property `serviceInspectFormat` specifies the default format for `docker
service inspect` output. When the `--format` flag is not provided with the
`docker service inspect` command, Docker's client uses this property. If this
@ -186,6 +192,7 @@ Following is a sample `config.json` file:
},
"psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
"imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
"pluginsFormat": "table {{.ID}}\t{{.Name}}\t{{.Enabled}}",
"statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
"serviceInspectFormat": "pretty",
"detachKeys": "ctrl-e,e",

View File

@ -24,8 +24,10 @@ Aliases:
ls, list
Options:
--help Print usage
--no-trunc Don't truncate output
--format string Pretty-print plugins using a Go template
--help Print usage
--no-trunc Don't truncate output
-q, --quiet Only display plugin IDs
```
Lists all the plugins that are currently installed. You can install plugins
@ -40,6 +42,32 @@ ID NAME TAG DESCRIP
69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker true
```
## Formatting
The formatting options (`--format`) pretty-prints plugins output
using a Go template.
Valid placeholders for the Go template are listed below:
Placeholder | Description
---------------|------------------------------------------------------------------------------------------
`.ID` | Plugin ID
`.Name` | Plugin name
`.Description` | Plugin description
`.Enabled` | Whether plugin is enabled or not
When using the `--format` option, the `plugin ls` command will either
output the data exactly as the template declares or, when using the
`table` directive, includes column headers as well.
The following example uses a template without headers and outputs the
`ID` and `Name` entries separated by a colon for all plugins:
```bash
$ docker plugin ls --format "{{.ID}}: {{.Name}}"
4be01827a72e: tiborvass/no-remove
```
## Related information
* [plugin create](plugin_create.md)