fix(cli/cliui): handle ptr to custom type (#16200)

This commit is contained in:
Mathias Fredriksson
2025-01-20 12:48:51 +00:00
committed by GitHub
parent 4ba0b39f03
commit 2913fe8677
2 changed files with 35 additions and 14 deletions
+16
View File
@@ -203,6 +203,10 @@ func renderTable(out any, sort string, headers table.Row, filterColumns []string
} else {
v = nil
}
case *string:
if val != nil {
v = *val
}
case *int64:
if val != nil {
v = *val
@@ -240,6 +244,18 @@ func renderTable(out any, sort string, headers table.Row, filterColumns []string
}
}
// Last resort, just get the interface value to avoid printing
// pointer values. For example, if we have a `*MyType("value")`
// which is defined as `type MyType string`, we want to print
// the string value, not the pointer.
if v != nil {
vv := reflect.ValueOf(v)
for vv.Kind() == reflect.Ptr && !vv.IsNil() {
vv = vv.Elem()
}
v = vv.Interface()
}
rowSlice[i] = v
}