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

Function markdownRows

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

Source from the content-addressed store, hash-verified

325}
326
327func markdownRows(data interface{}) ([]string, [][]string, bool) {
328 v := reflect.ValueOf(data)
329 if !v.IsValid() {
330 return nil, nil, false
331 }
332
333 if v.Kind() == reflect.Ptr {
334 if v.IsNil() {
335 return nil, nil, false
336 }
337 v = v.Elem()
338 }
339
340 switch v.Kind() {
341 case reflect.Slice:
342 if v.Len() == 0 {
343 return []string{"Result"}, [][]string{}, true
344 }
345
346 first := v.Index(0)
347 if first.Kind() == reflect.Ptr {
348 first = first.Elem()
349 }
350
351 switch first.Kind() {
352 case reflect.Struct:
353 headers := getStructHeaders(first)
354 rows := make([][]string, 0, v.Len())
355 for i := 0; i < v.Len(); i++ {
356 elem := v.Index(i)
357 if elem.Kind() == reflect.Ptr {
358 elem = elem.Elem()
359 }
360 rows = append(rows, escapeMarkdownRow(getStructValues(elem)))
361 }
362 return escapeMarkdownRow(headers), rows, true
363 case reflect.Map:
364 headers := getMapHeaders(first)
365 rows := make([][]string, 0, v.Len())
366 for i := 0; i < v.Len(); i++ {
367 elem := v.Index(i)
368 if elem.Kind() == reflect.Ptr {
369 elem = elem.Elem()
370 }
371 rows = append(rows, escapeMarkdownRow(getMapValues(elem, headers)))
372 }
373 return escapeMarkdownRow(headers), rows, true
374 default:
375 return nil, nil, false
376 }
377 case reflect.Struct:
378 headers := []string{"FIELD", "VALUE"}
379 rows := make([][]string, 0, v.NumField())
380 structHeaders := getStructHeaders(v)
381 structValues := getStructValues(v)
382 for i := range structHeaders {
383 rows = append(rows, escapeMarkdownRow([]string{structHeaders[i], structValues[i]}))
384 }

Callers 1

printMarkdownFunction · 0.85

Calls 5

getStructHeadersFunction · 0.85
escapeMarkdownRowFunction · 0.85
getStructValuesFunction · 0.85
getMapHeadersFunction · 0.85
getMapValuesFunction · 0.85

Tested by

no test coverage detected