feat(cli): emit the object itself for a request that named one resource - #372
shaked-bouktus wants to merge 2 commits into
Conversation
The machine formats wrapped every result in the {items, count} envelope, so
"kli definitions NAME -o yaml" emitted a list of one and did not pipe into
validate or kubectl apply without an unwrapping step.
The shape now follows the request rather than the result size, the way kubectl's
does: "definitions NAME" and "get TYPE/NAME" emit the object, while a filter or a
bare list keeps the envelope however many results come back. Keying off the
request and not the count is what makes the shape a function of the command line,
so a consumer walking items is never broken by a filter that happens to match
once.
Render keeps the envelope and RenderNamed emits the item, both over one
unexported render that takes the payload already shaped, so the two differ in
shape without duplicating the format switch. A named get resolves through a
client.Get that returns exactly one object or exits not-found, so the renderer
never sees an ambiguous named result.
Signed-off-by: sbouktus <sbouktus@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 WalkthroughWalkthroughChangesNamed definition and workload requests now emit standalone JSON or YAML objects when one item resolves. Collection requests retain the Named output rendering
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant CLI
participant RenderWorkloads
participant Render
participant JSONYAML
CLI->>RenderWorkloads: request named workload
RenderWorkloads->>Render: pass ByName and resolved items
Render->>JSONYAML: serialize one item directly
JSONYAML-->>CLI: return standalone JSON or YAML
Merge Risk: ⚪ Minimal · up to Named JSON/YAML output is consistently shaped as documented, with collection output preserved for list requests. The change is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
| // AllNamespaces drops the namespace from the empty-result message. | ||
| AllNamespaces bool | ||
| // Named reports that the request addressed one workload by name. | ||
| Named bool |
| if opts.Named && len(views) == 1 { | ||
| return RenderNamed(out, format, views[0], table) | ||
| } | ||
| return Render(out, format, views, table) |
There was a problem hiding this comment.
Consider handling this inside render.go so that outside callers don't need to check this and decide whether to call RenderNamed or Render.
| if len(args) == 1 { | ||
| return generator.RenderNamed(cmd.OutOrStdout(), output.Get(), kartas[0], table) | ||
| } | ||
| return generator.Render(cmd.OutOrStdout(), output.Get(), kartas, table) |
Render now takes a byName bool and decides the shape itself, so a caller hands it the result and the flag rather than picking between two functions and indexing into its own slice to call one of them. RenderNamed is gone. Options.Named becomes Options.ByName to match the parameter. Addresses review feedback on PR #372. Signed-off-by: sbouktus <sbouktus@nvidia.com>
What does this PR do?
Every result came back wrapped in the {items, count} envelope, so
"kli definitions NAME -o yaml" handed you a list of one. Piping that into
validate or kubectl apply meant unwrapping it first, which is a lot of
ceremony for something you already asked for by name.
The shape now follows what you asked for rather than what came back, same as
kubectl. Name a thing and you get the thing: "definitions NAME",
"get TYPE/NAME". Ask for a list and you get the envelope, even when only one
result matches. That last bit is the point of keying off the request instead
of the count - a script doing "jq .items[]" would otherwise break the day a
filter happened to match exactly once.
Render still wraps, RenderNamed does not, and both run through one unexported
render that takes the payload already shaped, so there is still only one
format switch. A named get goes through client.Get, which either returns one
object or exits not-found, so the renderer never has to guess which view to
emit.
Related issue(s)
Fixes #
Checklist
git commit -s)make check)Summary by CodeRabbit
New Features
itemswrapper.itemsenvelope.Documentation
kli definitionsdocumentation to clarify machine-readable output and validation.kli validate.Bug Fixes