A cloud resource printer - #17
Conversation
khisakuni
left a comment
There was a problem hiding this comment.
Couple comments regarding the cursor comments but otherwise lgtm!
| _, row := p.parseFields(resourceVal, options.Fields, []string{"Spec"}, 1) | ||
| _, specRow := p.parseFields(resourceVal.FieldByName("Spec"), options.SpecFields, nil, 1) | ||
| maps.Copy(row, specRow) | ||
| rows = append(rows, row) |
There was a problem hiding this comment.
Nil pointer slice element causes panic in PrintResourceList
Low Severity
In PrintResourceList, when a slice element is a nil pointer, resourceVal.Elem() produces a zero reflect.Value. While parseFields safely handles this (line 760 checks IsValid()), the subsequent call to resourceVal.FieldByName("Spec") on the zero value panics. The analogous code in colFieldReader (lines 563-566) correctly checks v.IsNil() before calling Elem(), but PrintResourceList lacks this guard.
| } | ||
| if isZero(v.Field(i).Interface()) { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Zero-value fields unconditionally hidden by PrintResource
High Severity
parseFields unconditionally skips all zero-value fields via isZero, but the old PrintStructured path only omits zero-value fields when cardOmitEmpty is explicitly set via struct tag. This causes PrintResource to silently drop meaningful false/zero values. Most notably, EnableDeleteProtection: false in the lifecycle get command is completely omitted from text output, making it impossible for users to confirm that delete protection is disabled.
Additional Locations (1)
There was a problem hiding this comment.
IMO print resource needs to be more human friendly, and with out this check it will print a lot of noise thats not idea. But i do get understand the risk of not printing zero values. Lets keep things as is for now and revisit this later.


Note
Medium Risk
Touches core CLI output formatting and reflection-based printing paths, so regressions could affect many commands’ human-readable output (though JSON output remains largely passthrough and changes are well-covered by tests).
Overview
Introduces a new resource-aware printer API:
PrintResourcerenders structs as metadata + indentedSpec, andPrintResourceListrenders list responses as stable tables (with optional NextPageToken output) while preserving existing JSON behavior.Enhances text rendering via pluggable converters (including built-in enum-to-string mapping for
ResourceStateandAsyncOperationstate registered at CLI startup), improves nil/zero-value handling in table/card printing, and changesPrintDiffto emit structured JSON{before, after}when in JSON mode.Updates namespace
get,list, and lifecyclegetcommands to use the new resource printing functions and to show selected fields/spec fields for list output; expandsprintertests substantially to cover these new behaviors and edge cases.Written by Cursor Bugbot for commit 778f5c9. This will update automatically on new commits. Configure here.