feat(cli): add streaming list output and man Doc.AddStringFlag helper - #3805
feat(cli): add streaming list output and man Doc.AddStringFlag helper#3805alkalescent wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds ChangesStreaming CLI output
Documented flag registration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Iterator as iter.Seq2
participant CLI as Cli.StreamList
participant Writer as io.Writer
Iterator->>CLI: yield item or error
CLI->>Writer: write JSON item or table output
Writer-->>CLI: return write result
CLI-->>Iterator: stop on iterator error
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add Cli.StreamList for rendering large lists incrementally: a memory-bounded JSON array in JSON mode, and a tabwriter-aligned table in styled mode. Items are supplied as an iter.Seq2[any, error] so a failed page fetch aborts the stream and propagates to the caller rather than looking like normal exhaustion. Add man.Doc.AddStringFlag to register a string flag from its doc definition in one call, reducing per-flag boilerplate in commands with many flags.
5b54b1c to
57d0ba7
Compare
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Replace the tabwriter styled path in StreamList with a lipgloss/table render so styled output matches the rounded, indigo-bordered look of NewTable. The tabwriter path already buffered all rows until Flush, so buffering rows for a one-shot styled render costs the same memory while restoring borders and cell styling; the JSON branch stays streamed and memory-bounded. lipgloss/table needs no bubbletea and stays terminal-width-agnostic. Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@otdfctl/pkg/cli/stream.go`:
- Around line 52-66: Update the separator values in the stream item writing loop
to use "\n" for the first item and ",\n" for subsequent items, avoiding
duplicate indentation from marshalStreamItem. Add an exact-output assertion to
TestStreamListJSON covering the corrected formatting.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c01a3747-8e37-4d0b-8271-f1df24da58a0
📒 Files selected for processing (4)
otdfctl/pkg/cli/stream.gootdfctl/pkg/cli/stream_test.gootdfctl/pkg/man/docflags.gootdfctl/pkg/man/docflags_test.go
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Add an exact-output assertion to TestStreamListJSON so the array indentation is guarded against regression. SetIndent does not prefix an object's opening brace, so the item separators supply the two-space indent that aligns each object with printJSON; the golden string locks that layout in. Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
Summary
Two small, reusable additions to otdfctl, both prompted by CLI work that registers many flags and lists potentially large result sets:
Cli.StreamList(pkg/cli/stream.go) — renders a list incrementally. In JSON mode it writes a JSON array, marshaling one item at a time so the full result set is never buffered (memory-bounded, suitable for very large lists). In styled mode it writes atext/tabwriter-aligned table; that path buffers rows to align columns, so JSON mode is the memory-bounded path. Takes aniter.Seq[any]so callers can feed a paged iterator without materializing it.man.Doc.AddStringFlag(pkg/man/docflags.go) — registers a string flag on a command from its doc definition in one call, replacing the repeatedcmd.Flags().StringP(doc.GetDocFlag("x").Name, …Shorthand, …Default, …Description)boilerplate seen acrosscmd/.Test plan
go test ./pkg/man/... ./pkg/cli/... -racepasses (new unit tests cover JSON/styled streaming, empty input, HTML-escape parity, and the flag helper including its panic-on-unknown path).golangci-lint run ./pkg/man/... ./pkg/cli/...clean.Summary by CodeRabbit
New Features
Bug Fixes
Tests