MCPcopy Index your code
hub / github.com/docker/cli / buildContainerListOptions

Function buildContainerListOptions

cli/command/container/list.go:71–115  ·  view source on GitHub ↗
(options *psOptions)

Source from the content-addressed store, hash-verified

69}
70
71func buildContainerListOptions(options *psOptions) (client.ContainerListOptions, error) {
72 listOptions := client.ContainerListOptions{
73 All: options.all,
74 Limit: options.last,
75 Size: options.size,
76 Filters: options.filter.Value(),
77 }
78
79 if options.nLatest && options.last == -1 {
80 listOptions.Limit = 1
81 }
82
83 // always validate template when `--format` is used, for consistency
84 if len(options.format) > 0 {
85 tmpl, err := templates.Parse(options.format)
86 if err != nil {
87 return client.ContainerListOptions{}, fmt.Errorf("failed to parse template: %w", err)
88 }
89
90 optionsProcessor := formatter.NewContainerContext()
91
92 // This shouldn't error out but swallowing the error makes it harder
93 // to track down if preProcessor issues come up.
94 if err := tmpl.Execute(io.Discard, optionsProcessor); err != nil {
95 return client.ContainerListOptions{}, fmt.Errorf("failed to execute template: %w", err)
96 }
97
98 // if `size` was not explicitly set to false (with `--size=false`)
99 // and `--quiet` is not set, request size if the template requires it
100 if !options.quiet && !listOptions.Size && !options.sizeChanged {
101 // The --size option isn't set, but .Size may be used in the template.
102 // Parse and execute the given template to detect if the .Size field is
103 // used. If it is, then automatically enable the --size option. See #24696
104 //
105 // Only requesting container size information when needed is an optimization,
106 // because calculating the size is a costly operation.
107
108 if _, ok := optionsProcessor.FieldsUsed["Size"]; ok {
109 listOptions.Size = true
110 }
111 }
112 }
113
114 return listOptions, nil
115}
116
117func runPs(ctx context.Context, dockerCLI command.Cli, options *psOptions) error {
118 if len(options.format) == 0 {

Callers 2

runPsFunction · 0.85

Calls 1

ValueMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…