MCPcopy
hub / github.com/docker/compose / Print

Function Print

cmd/formatter/formatter.go:29–71  ·  cmd/formatter/formatter.go::Print

Print prints formatted lists in different formats

(toJSON any, format string, outWriter io.Writer, writerFn func(w io.Writer), headers ...string)

Source from the content-addressed store, hash-verified

27
28// Print prints formatted lists in different formats
29func Print(toJSON any, format string, outWriter io.Writer, writerFn func(w io.Writer), headers ...string) error {
30 switch strings.ToLower(format) {
31 case TABLE, PRETTY, "":
32 return PrintPrettySection(outWriter, writerFn, headers...)
33 case TemplateLegacyJSON:
34 switch reflect.TypeOf(toJSON).Kind() {
35 case reflect.Slice:
36 s := reflect.ValueOf(toJSON)
37 for i := 0; i < s.Len(); i++ {
38 obj := s.Index(i).Interface()
39 outJSON, err := ToJSON(obj, "", "")
40 if err != nil {
41 return err
42 }
43 _, _ = fmt.Fprint(outWriter, outJSON)
44 }
45 default:
46 outJSON, err := ToStandardJSON(toJSON)
47 if err != nil {
48 return err
49 }
50 _, _ = fmt.Fprintln(outWriter, outJSON)
51 }
52 case JSON:
53 switch reflect.TypeOf(toJSON).Kind() {
54 case reflect.Slice:
55 outJSON, err := ToJSON(toJSON, "", "")
56 if err != nil {
57 return err
58 }
59 _, _ = fmt.Fprint(outWriter, outJSON)
60 default:
61 outJSON, err := ToStandardJSON(toJSON)
62 if err != nil {
63 return err
64 }
65 _, _ = fmt.Fprintln(outWriter, outJSON)
66 }
67 default:
68 return fmt.Errorf("format value %q could not be parsed: %w", format, api.ErrParsingFailed)
69 }
70 return nil
71}

Callers 5

displayTransformerFunction · 0.92
runVariablesFunction · 0.92
runImagesFunction · 0.92
runListFunction · 0.92
TestPrintFunction · 0.85

Calls 4

PrintPrettySectionFunction · 0.85
ToJSONFunction · 0.85
ToStandardJSONFunction · 0.85
LenMethod · 0.80

Tested by 1

TestPrintFunction · 0.68