Add --format to docker-search

Signed-off-by: Jeremy Chambers <jeremy@thehipbot.com>
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
This commit is contained in:
Boaz Shuster
2017-08-15 13:58:49 +03:00
parent 703a7cca2b
commit 88cc47ad5c
4 changed files with 452 additions and 29 deletions

View File

@ -25,6 +25,7 @@ Options:
- is-automated=(true|false)
- is-official=(true|false)
- stars=<number> - image has at least 'number' stars
--format string Pretty-print images using a Go template
--help Print usage
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
@ -144,3 +145,58 @@ NAME DESCRIPTION STARS O
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]
```
### Format the output
The formatting option (`--format`) pretty-prints search output
using a Go template.
Valid placeholders for the Go template are:
| Placeholder | Description |
| -------------- | --------------------------------- |
| `.Name` | Image Name |
| `.Description` | Image description |
| `.StarCount` | Number of stars for the image |
| `.IsOfficial` | "OK" if image is official |
| `.IsAutomated` | "OK" if image build was automated |
When you use the `--format` option, the `search` command will
output the data exactly as the template declares. If you use the
`table` directive, column headers are included as well.
The following example uses a template without headers and outputs the
`Name` and `StarCount` entries separated by a colon for all images:
```bash
{% raw %}
$ docker search --format "{{.Name}}: {{.StarCount}}" nginx
nginx: 5441
jwilder/nginx-proxy: 953
richarvey/nginx-php-fpm: 353
million12/nginx-php: 75
webdevops/php-nginx: 70
h3nrik/nginx-ldap: 35
bitnami/nginx: 23
evild/alpine-nginx: 14
million12/nginx: 9
maxexcloo/nginx: 7
{% endraw %}
```
This example outputs a table format:
```bash
{% raw %}
$ docker search --format "table {{.Name}}\t{{.IsAutomated}}\t{{.IsOfficial}}" nginx
NAME AUTOMATED OFFICIAL
nginx [OK]
jwilder/nginx-proxy [OK]
richarvey/nginx-php-fpm [OK]
jrcs/letsencrypt-nginx-proxy-companion [OK]
million12/nginx-php [OK]
webdevops/php-nginx [OK]
{% endraw %}
```