MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / Print

Function Print

internal/cmd/plugin/printer.go:30–62  ·  view source on GitHub ↗

Print output an object via an io.Writer in a machine-readable way

(o interface{}, format OutputFormat, writer io.Writer)

Source from the content-addressed store, hash-verified

28
29// Print output an object via an io.Writer in a machine-readable way
30func Print(o interface{}, format OutputFormat, writer io.Writer) error {
31 switch format {
32 case OutputFormatJSON:
33 data, err := json.MarshalIndent(o, "", " ")
34 if err != nil {
35 return err
36 }
37
38 _, err = writer.Write(data)
39 if err != nil {
40 return err
41 }
42
43 // json.MarshalIndent doesn't add the final newline
44 _, err = io.WriteString(writer, "\n")
45 if err != nil {
46 return err
47 }
48
49 case OutputFormatYAML:
50 data, err := yaml.Marshal(o)
51 if err != nil {
52 return err
53 }
54
55 _, err = writer.Write(data)
56 if err != nil {
57 return err
58 }
59 }
60
61 return nil
62}

Callers 6

GenerateFunction · 0.92
StatusFunction · 0.92
addContentToZipFunction · 0.92
addObjectsToZipFunction · 0.92
executeMethod · 0.92
CreateAndGenerateObjectsFunction · 0.85

Calls 1

WriteMethod · 0.65

Tested by

no test coverage detected