(w io.Writer, b []byte, format rawOutputFormat)
| 82 | } |
| 83 | |
| 84 | func 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 | |
| 112 | func isJSON(str []byte) bool { |
| 113 | var js json.RawMessage |
no outgoing calls
no test coverage detected