moby/api/client
Paulo Ribeiro 55cdb6dcd0
Add a check for size field in custom format string
This fix addresses an issue where including the `{{.Size}}` format
field in conjunction with `docker ps --format`, without the `--size`
flag, would not correctly display the size of containers.

This is done by doing a check on the custom format string, and setting
the size flag on the options struct if the field is found. This struct
gets passed to the engine API which then generates the correct query.

An integration test is included which runs `docker ps --format "table
{{.Size}}"` without `--size`, and checks that the returned output is
not `0 B`.

Fixes #21991

As suggested by @cpuguy83, a parser is implemented to process the format
string as a template, and then traverses the template tree to determine
if `.Size` was called.

This was then reworked by making use of template execution with a
pre-processor struct that will set the `--size` option if the template
calls for the field.

The pre-processor now also sets a boolean in the context passed to the
writer. There is an integration test for this that calls `docker ps
--size --format "{{.Size}}"` and then checks that `size: {{.Size}}` is
not appended, as it would with previous behavior.

Finally, a change was made to the formatter to not automatically
add a `{{.Size}}` if a custom format is provided.

Signed-off-by: Paulo Ribeiro <paigr.io@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2016-06-03 21:59:10 +02:00
..
formatter Add a check for size field in custom format string 2016-06-03 21:59:10 +02:00
inspect Refactor cli inspector to support new inspects. 2016-05-31 14:41:37 -07:00
volume Use Args in cobra.Command to validate args. 2016-05-31 15:43:16 -07:00
attach.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
build.go Un-deprecated command line short variant options of -c. 2016-05-26 08:22:27 -07:00
cli.go Migrate volume commands to cobra. 2016-05-31 14:41:37 -07:00
client.go Make sure docker api client implements engine-api client. 2016-01-07 21:02:19 -05:00
commands.go Migrate volume commands to cobra. 2016-05-31 14:41:37 -07:00
commit.go Update client code with api changes 2016-04-15 12:48:01 +02:00
cp.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
create.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
diff.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
events.go Remove some unused structs and fields 2016-03-01 09:59:29 -08:00
exec.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
exec_test.go Update client code with api changes 2016-04-15 12:48:01 +02:00
export.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
hijack.go cli: move setRawTerminal and restoreTerminal to holdHijackedConnection 2016-03-24 21:25:50 -04:00
history.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
images.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
import.go Update client code with api changes 2016-04-15 12:48:01 +02:00
info.go make Insecure registries uppercase like other keys in docker info 2016-04-25 18:44:34 +08:00
inspect.go Refactor cli inspector to support new inspects. 2016-05-31 14:41:37 -07:00
kill.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
load.go Fix docker load progressbar, fixes #21957 2016-04-12 22:45:42 -04:00
login.go Error login from non TTY 2016-05-25 09:29:50 -07:00
logout.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
logs.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
network.go Refactor cli inspector to support new inspects. 2016-05-31 14:41:37 -07:00
pause.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
port.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
ps.go Add a check for size field in custom format string 2016-06-03 21:59:10 +02:00
pull.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
push.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
rename.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
restart.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
rm.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
rmi.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
run.go Update ContainerStart calls to use options now 2016-06-02 16:56:13 +02:00
save.go Apply context changes to the client. 2016-02-04 13:59:57 -05:00
search.go Add --limit option to docker search 2016-06-02 19:12:20 -07:00
start.go Update ContainerStart calls to use options now 2016-06-02 16:56:13 +02:00
stats.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
stats_helpers.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
stats_unit_test.go Do not remove containers from stats list on err 2016-04-13 16:36:34 -04:00
stop.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
tag.go Remove deprecated -f flag on docker tag 2016-06-01 09:44:25 -07:00
top.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
trust.go fix typos 2016-06-02 17:17:22 +08:00
trust_test.go Modify import paths to point to the new engine-api package. 2016-01-06 19:48:59 -05:00
unpause.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
update.go Un-deprecated command line short variant options of -c. 2016-05-26 08:22:27 -07:00
utils.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00
version.go Update api/client file to use context 2016-03-16 20:25:09 +01:00
wait.go Rework usage of context.Context in api/client 2016-05-21 15:57:57 +02:00