(output io.Writer, info dockerInfo, format string)
| 481 | } |
| 482 | |
| 483 | func formatInfo(output io.Writer, info dockerInfo, format string) error { |
| 484 | if format == formatter.JSONFormatKey { |
| 485 | format = formatter.JSONFormat |
| 486 | } |
| 487 | |
| 488 | // Ensure slice/array fields render as `[]` not `null` |
| 489 | if info.ClientInfo != nil && info.ClientInfo.Plugins == nil { |
| 490 | info.ClientInfo.Plugins = make([]pluginmanager.Plugin, 0) |
| 491 | } |
| 492 | |
| 493 | tmpl, err := templates.Parse(format) |
| 494 | if err != nil { |
| 495 | return cli.StatusError{ |
| 496 | StatusCode: 64, |
| 497 | Status: "template parsing error: " + err.Error(), |
| 498 | } |
| 499 | } |
| 500 | err = tmpl.Execute(output, info) |
| 501 | fprintln(output) |
| 502 | return err |
| 503 | } |
| 504 | |
| 505 | func fprintf(w io.Writer, format string, a ...any) { |
| 506 | _, _ = fmt.Fprintf(w, format, a...) |
searching dependent graphs…