MCPcopy
hub / github.com/hasura/graphql-engine / writeByOutputFormat

Function writeByOutputFormat

cli/commands/metadata.go:84–110  ·  view source on GitHub ↗
(w io.Writer, b []byte, format rawOutputFormat)

Source from the content-addressed store, hash-verified

82}
83
84func writeByOutputFormat(w io.Writer, b []byte, format rawOutputFormat) error {
85 var op errors.Op = "commands.writeByOutputFormat"
86 switch format {
87 case rawOutputFormatJSON:
88 out := new(bytes.Buffer)
89 err := json.Indent(out, b, "", " ")
90 if err != nil {
91 return errors.E(op, err)
92 }
93 _, err = io.Copy(w, out)
94 if err != nil {
95 return errors.E(op, fmt.Errorf("writing output failed: %w", err))
96 }
97 case rawOutputFormatYAML:
98 o, err := metadatautil.JSONToYAML(b)
99 if err != nil {
100 return errors.E(op, err)
101 }
102 _, err = io.Copy(w, bytes.NewReader(o))
103 if err != nil {
104 return errors.E(op, fmt.Errorf("writing output failed: %w", err))
105 }
106 default:
107 return errors.E(op, fmt.Errorf("output format '%v' is not supported. supported formats: %v, %v", format, rawOutputFormatJSON, rawOutputFormatYAML))
108 }
109 return nil
110}
111
112func isJSON(str []byte) bool {
113 var js json.RawMessage

Callers 3

ApplyMethod · 0.85
applyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected