Commit 4e31781
committed
history ls: fix '--format' flag to accept go templates
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 <github@gone.nl>1 parent 06b1d87 commit 4e31781
File tree
3 files changed
+34
-33
lines changed- commands/history
- docs/reference
3 files changed
+34
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
111 | | - | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
192 | 193 | | |
193 | | - | |
194 | | - | |
| 194 | + | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | | - | |
| 201 | + | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
204 | | - | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
208 | | - | |
| 209 | + | |
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
216 | | - | |
217 | | - | |
| 217 | + | |
| 218 | + | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| |||
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
226 | | - | |
| 227 | + | |
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
230 | | - | |
231 | | - | |
232 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | | - | |
239 | | - | |
| 239 | + | |
| 240 | + | |
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments