NewContainerFormat returns a Format for rendering using a Context
(source string, quiet bool, size bool)
| 42 | |
| 43 | // NewContainerFormat returns a Format for rendering using a Context |
| 44 | func NewContainerFormat(source string, quiet bool, size bool) Format { |
| 45 | switch source { |
| 46 | case TableFormatKey, "": // table formatting is the default if none is set. |
| 47 | if quiet { |
| 48 | return DefaultQuietFormat |
| 49 | } |
| 50 | format := defaultContainerTableFormat |
| 51 | if size { |
| 52 | format += `\t{{.Size}}` |
| 53 | } |
| 54 | return Format(format) |
| 55 | case RawFormatKey: |
| 56 | if quiet { |
| 57 | return `container_id: {{.ID}}` |
| 58 | } |
| 59 | format := `container_id: {{.ID}} |
| 60 | image: {{.Image}} |
| 61 | command: {{.Command}} |
| 62 | created_at: {{.CreatedAt}} |
| 63 | state: {{- pad .State 1 0}} |
| 64 | status: {{- pad .Status 1 0}} |
| 65 | names: {{.Names}} |
| 66 | labels: {{- pad .Labels 1 0}} |
| 67 | ports: {{- pad .Ports 1 0}} |
| 68 | ` |
| 69 | if size { |
| 70 | format += `size: {{.Size}}\n` |
| 71 | } |
| 72 | return Format(format) |
| 73 | default: // custom format |
| 74 | if quiet { |
| 75 | return DefaultQuietFormat |
| 76 | } |
| 77 | return Format(source) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // ContainerWrite renders the context for a list of containers |
| 82 | func ContainerWrite(ctx Context, containers []container.Summary) error { |
searching dependent graphs…