MCPcopy Create free account
hub / github.com/docker/cli / NewContainerFormat

Function NewContainerFormat

cli/command/formatter/container.go:44–79  ·  view source on GitHub ↗

NewContainerFormat returns a Format for rendering using a Context

(source string, quiet bool, size bool)

Source from the content-addressed store, hash-verified

42
43// NewContainerFormat returns a Format for rendering using a Context
44func 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}}
60image: {{.Image}}
61command: {{.Command}}
62created_at: {{.CreatedAt}}
63state: {{- pad .State 1 0}}
64status: {{- pad .Status 1 0}}
65names: {{.Names}}
66labels: {{- pad .Labels 1 0}}
67ports: {{- 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
82func ContainerWrite(ctx Context, containers []container.Summary) error {

Callers 3

NewDiskUsageFormatFunction · 0.85

Calls 1

FormatTypeAlias · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…