MCPcopy Create free account
hub / github.com/github/gh-aw / buildTableRows

Function buildTableRows

pkg/console/render.go:320–348  ·  view source on GitHub ↗

buildTableRows builds the row data for a slice of struct elements.

(val reflect.Value, fieldPaths [][]int, fieldTags []consoleTag)

Source from the content-addressed store, hash-verified

318
319// buildTableRows builds the row data for a slice of struct elements.
320func buildTableRows(val reflect.Value, fieldPaths [][]int, fieldTags []consoleTag) [][]string {
321 var rows [][]string
322 for i := range val.Len() {
323 elem := val.Index(i)
324 // Dereference pointer if needed
325 for elem.Kind() == reflect.Pointer {
326 if elem.IsNil() {
327 break
328 }
329 elem = elem.Elem()
330 }
331
332 if elem.Kind() != reflect.Struct {
333 continue
334 }
335
336 var row []string
337 for j, fieldPath := range fieldPaths {
338 field, ok := fieldByIndexSafe(elem, fieldPath)
339 if !ok {
340 row = append(row, "")
341 continue
342 }
343 row = append(row, formatFieldValueWithTag(field, fieldTags[j]))
344 }
345 rows = append(rows, row)
346 }
347 return rows
348}
349
350func fieldByIndexSafe(val reflect.Value, path []int) (reflect.Value, bool) {
351 current := val

Callers 1

buildTableConfigFunction · 0.85

Calls 2

fieldByIndexSafeFunction · 0.85
formatFieldValueWithTagFunction · 0.85

Tested by

no test coverage detected