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