(containers []container.ListItem, options FormattingAndPrintingOptions)
| 155 | } |
| 156 | |
| 157 | func formatAndPrintContainerInfo(containers []container.ListItem, options FormattingAndPrintingOptions) error { |
| 158 | w := options.Stdout |
| 159 | var ( |
| 160 | wide bool |
| 161 | tmpl *template.Template |
| 162 | ) |
| 163 | switch options.Format { |
| 164 | case "", "table": |
| 165 | w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0) |
| 166 | if !options.Quiet { |
| 167 | printHeader := "CONTAINER ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tNAMES" |
| 168 | if options.Size { |
| 169 | printHeader += "\tSIZE" |
| 170 | } |
| 171 | fmt.Fprintln(w, printHeader) |
| 172 | } |
| 173 | case "raw": |
| 174 | return errors.New("unsupported format: \"raw\"") |
| 175 | case "wide": |
| 176 | w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0) |
| 177 | if !options.Quiet { |
| 178 | fmt.Fprintln(w, "CONTAINER ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tNAMES\tRUNTIME\tPLATFORM\tSIZE") |
| 179 | wide = true |
| 180 | } |
| 181 | default: |
| 182 | if options.Quiet { |
| 183 | return errors.New("format and quiet must not be specified together") |
| 184 | } |
| 185 | var err error |
| 186 | tmpl, err = formatter.ParseTemplate(options.Format) |
| 187 | if err != nil { |
| 188 | return err |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | for _, c := range containers { |
| 193 | if tmpl != nil { |
| 194 | var b bytes.Buffer |
| 195 | if err := tmpl.Execute(&b, &c); err != nil { |
| 196 | return err |
| 197 | } |
| 198 | if _, err := fmt.Fprintln(w, b.String()); err != nil { |
| 199 | return err |
| 200 | } |
| 201 | } else if options.Quiet { |
| 202 | if _, err := fmt.Fprintln(w, c.ID); err != nil { |
| 203 | return err |
| 204 | } |
| 205 | } else { |
| 206 | format := "%s\t%s\t%s\t%s\t%s\t%s\t%s" |
| 207 | args := []interface{}{ |
| 208 | c.ID, |
| 209 | c.Image, |
| 210 | c.Command, |
| 211 | formatter.TimeSinceInHuman(c.CreatedAt), |
| 212 | c.Status, |
| 213 | c.Ports, |
| 214 | c.Names, |
no test coverage detected
searching dependent graphs…