MCPcopy Create free account
hub / github.com/AndroidPoet/playconsole-cli / printCSV

Function printCSV

internal/output/output.go:244–281  ·  view source on GitHub ↗
(data interface{})

Source from the content-addressed store, hash-verified

242}
243
244func printCSV(data interface{}) error {
245 w := csv.NewWriter(writer)
246 defer w.Flush()
247
248 v := reflect.ValueOf(data)
249
250 if v.Kind() == reflect.Slice {
251 if v.Len() == 0 {
252 return nil
253 }
254
255 // Print header
256 first := v.Index(0)
257 if first.Kind() == reflect.Ptr {
258 first = first.Elem()
259 }
260 headers := getStructHeaders(first)
261 if err := w.Write(headers); err != nil {
262 return fmt.Errorf("failed to write CSV header: %w", err)
263 }
264
265 // Print rows
266 for i := 0; i < v.Len(); i++ {
267 elem := v.Index(i)
268 if elem.Kind() == reflect.Ptr {
269 elem = elem.Elem()
270 }
271 values := getStructValues(elem)
272 if err := w.Write(values); err != nil {
273 return fmt.Errorf("failed to write CSV row: %w", err)
274 }
275 }
276 } else {
277 return printJSON(data)
278 }
279
280 return nil
281}
282
283func printYAML(data interface{}) error {
284 out, err := yaml.Marshal(data)

Callers 1

PrintFunction · 0.85

Calls 3

getStructHeadersFunction · 0.85
getStructValuesFunction · 0.85
printJSONFunction · 0.85

Tested by

no test coverage detected