Repository navigation
cmd: multiple formats output support for du command - #3377
Conversation
tonistiigi
left a comment
There was a problem hiding this comment.
Although this is what user asked, I think it would be weird if this worked differently than --format in other commands. So it should work with template but also the json shorthand.
Yes you right and also shouldn't be an array, I will change that. |
28196cd to
9af0a0c
Compare
| func printKV(w io.Writer, k string, v any) { | ||
| fmt.Fprintf(w, "%s:\t%v\n", k, v) | ||
| } | ||
|
|
||
| func printVerbose(tw *tabwriter.Writer, du []*client.UsageInfo) { | ||
| for _, di := range du { | ||
| printKV(tw, "ID", di.ID) | ||
| if len(di.Parents) != 0 { | ||
| printKV(tw, "Parent", strings.Join(di.Parents, ",")) | ||
| } | ||
| printKV(tw, "Created at", di.CreatedAt) | ||
| printKV(tw, "Mutable", di.Mutable) | ||
| printKV(tw, "Reclaimable", !di.InUse) | ||
| printKV(tw, "Shared", di.Shared) | ||
| printKV(tw, "Size", units.HumanSize(float64(di.Size))) | ||
| if di.Description != "" { | ||
| printKV(tw, "Description", di.Description) | ||
| } | ||
| printKV(tw, "Usage count", di.UsageCount) | ||
| if di.LastUsedAt != nil { | ||
| printKV(tw, "Last used", units.HumanDuration(time.Since(*di.LastUsedAt))+" ago") | ||
| } | ||
| if di.RecordType != "" { | ||
| printKV(tw, "Type", di.RecordType) | ||
| } | ||
|
|
||
| fmt.Fprintf(tw, "\n") | ||
| } | ||
|
|
||
| tw.Flush() | ||
| } | ||
|
|
||
| func printTableHeader(tw *tabwriter.Writer) { | ||
| fmt.Fprintln(tw, "ID\tRECLAIMABLE\tSIZE\tLAST ACCESSED") | ||
| } | ||
|
|
||
| func printTableRow(tw *tabwriter.Writer, di *client.UsageInfo) { | ||
| id := di.ID | ||
| if di.Mutable { | ||
| id += "*" | ||
| } | ||
| size := units.HumanSize(float64(di.Size)) | ||
| if di.Shared { | ||
| size += "*" | ||
| } | ||
| lastAccessed := "" | ||
| if di.LastUsedAt != nil { | ||
| lastAccessed = units.HumanDuration(time.Since(*di.LastUsedAt)) + " ago" | ||
| } | ||
| fmt.Fprintf(tw, "%-40s\t%-5v\t%-10s\t%s\n", id, !di.InUse, size, lastAccessed) | ||
| } |
There was a problem hiding this comment.
Moved logic not used anymore to prune command for now but we should also consider using docker/cli formatter for this command.
tonistiigi
left a comment
There was a problem hiding this comment.
If I do --format=table then I get empty rows, so it seems to know that this input is special but not handle it correctly. This could be follow-up.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
| } else if opts.format == formatter.TableFormatKey { | ||
| opts.format = duDefaultTableFormat | ||
| } |
There was a problem hiding this comment.
If I do
--format=tablethen I get empty rows, so it seems to know that this input is special but not handle it correctly. This could be follow-up.
@tonistiigi fixed here
Before you do, please check; we're trying to move many parts in the CLI internal, as there were too many things public that caused us not being able to make changes; for some we could find a new place though. Also considering if the CLI should execute buildx for performing prune instead of using the moby REST API (as part of |
fixes #3367
Adds
formatflag to support multiple formats output using docker/cli formatter.verboseflag is now a shorthand for--format=pretty.