history ls: fix '--format' flag to accept go templates#3683
Draft
thaJeztah wants to merge 3 commits intodocker:masterfrom
Draft
history ls: fix '--format' flag to accept go templates#3683thaJeztah wants to merge 3 commits intodocker:masterfrom
thaJeztah wants to merge 3 commits intodocker:masterfrom
Conversation
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Before this PR, attempting to use a format template would always fail;
```bash
docker buildx history ls --no-trunc --format 'table {{.Status}}\t{{.NumTotalSteps}}\t{{.Duration}}\t{{.Name}}'
ERROR: template parsing error: template: :1:14: executing "" at <.NumTotalSteps>: can't evaluate field NumTotalSteps in type *history.lsContext
```
With this PR, formatting works (mostly); the formatting templates don't
match the JSON response (which can be confusing), and not all fields have
a table defined (which can result in `<no value>` used).
```bash
docker buildx history ls --no-trunc --format 'table {{.Status}}\t{{.NumTotalSteps}}\t{{.Duration}}\t{{.Name}}'
STATUS <no value> DURATION NAME
Completed 16 17.1s buildx (binaries)
Completed 12 19.9s buildkit/hack/dockerfiles/vendor.Dockerfile (update)
Completed 123 28.7s docker (dev-base)
Completed 26 7.9s
Completed 12 2m 41s cli/dockerfiles/Dockerfile.vendor (update)
```
Or a slightly more adventurous;
```bash
docker buildx history ls --no-trunc --format '{{printf "{\"status\":%s,\"steps\":%s,\"duration\":%s,\"name\":%s}" (json .Status) (json .NumTotalSteps) (json .Duration) (json .Name)}}'
{"status":"Completed","steps":16,"duration":"17.1s","name":"buildx (binaries)"}
{"status":"Completed","steps":12,"duration":"19.9s","name":"buildkit/hack/dockerfiles/vendor.Dockerfile (update)"}
{"status":"Completed","steps":123,"duration":"28.7s","name":"docker (dev-base)"}
{"status":"Completed","steps":26,"duration":"7.9s","name":""}
{"status":"Completed","steps":12,"duration":"2m 41s","name":"cli/dockerfiles/Dockerfile.vendor (update)"}
{"status":"Error","steps":11,"duration":"3m 14s","name":"cli/dockerfiles/Dockerfile.vendor (update)"}
```
The flag description has been updated to align with other `--format` flags;
```bash
docker buildx history ls --help
Usage: docker buildx history ls [OPTIONS]
List build records
Options:
--builder string Override the configured builder instance
-D, --debug Enable debug logging
--filter stringArray Provide filter values (e.g., "status=error")
--format string Format output using a custom template:
'table': Print output in table format with column headers (default)
'table TEMPLATE': Print output in table format using the given Go template
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about
formatting output with templates (default "table")
--local List records for current repository only
--no-trunc Don't truncate output
```
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Member
Author
|
Ugh; we should disable this linter; it's too opinionated; in this case it's also .. wrong because there's fields being shadowed by wrappers 🤔 I'll push a "WIP" commit, but may open a PR to disable this linter (I know we disabled it elsewhere). |
Signed-off-by: Sebastiaan van Stijn <[email protected]>
4e31781 to
db5f3fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this PR, attempting to use a format template would always fail;
With this PR, formatting works (mostly); the formatting templates don't match the JSON response (which can be confusing), and not all fields have a table defined (which can result in
<no value>used).Or a slightly more adventurous;
The flag description has been updated to align with other
--formatflags;