feat: add --output text/json/yaml to config view commands#2017
feat: add --output text/json/yaml to config view commands#2017gengyi1207-bit wants to merge 6 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughConfiguration view output now supports text, JSON, and YAML formats through shared parsing and rendering helpers. The ChangesConfiguration view output
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant ConfigCommand
participant ParseViewFormat
participant WriteView
User->>ConfigCommand: Run config view command with --output
ConfigCommand->>ParseViewFormat: Parse requested format
ParseViewFormat-->>ConfigCommand: Return ViewFormat
ConfigCommand->>WriteView: Provide view data and text renderer
WriteView-->>User: Render text, JSON, or YAML output
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@internal/output/view_format.go`:
- Around line 41-42: Update the invalid-format validation error in
internal/output/view_format.go:41-42 to set Param to "output". In
internal/output/view_format_test.go:40-49, cmd/config/default_as_test.go:84-96,
and cmd/config/strict_mode_test.go:214-226, assert the validation category,
subtype, and ValidationError.Param using errors.As rather than errs.ProblemOf,
preserving the existing test behavior.
- Around line 53-67: Update WriteView to wrap raw errors from JSON
Encoder.Encode, YAML writer.Write, and renderText with errs internal errors
using WithCause(err), while returning existing typed errors unchanged. Apply the
wrapping consistently across all format branches without changing successful
rendering behavior.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: c1148c0d-8a4a-44b7-a4e5-e0a8a9dbca8d
📒 Files selected for processing (6)
cmd/config/default_as.gocmd/config/default_as_test.gocmd/config/strict_mode.gocmd/config/strict_mode_test.gointernal/output/view_format.gointernal/output/view_format_test.go
Per CodeRabbit review: attach Param="output" to the invalid --output validation error so callers can identify the failing flag, and wrap raw JSON/YAML/text write failures in WriteView as typed errs internal errors (preserving already-typed errors via errs.ProblemOf).
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 `@cmd/config/default_as_test.go`:
- Around line 97-99: Update the command error-path test around the existing
errors.As validation to also assert errs.ProblemOf(err) matches the expected
category and subtype, while retaining the *errs.ValidationError assertion for
Param == "output".
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 37dd7dc7-d7f2-40f9-8dc3-11eafdc407e1
📒 Files selected for processing (4)
cmd/config/default_as_test.gocmd/config/strict_mode_test.gointernal/output/view_format.gointernal/output/view_format_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
- internal/output/view_format.go
- internal/output/view_format_test.go
- cmd/config/strict_mode_test.go
…tion tests Per CodeRabbit review: pair the existing errors.As/Param assertion with an errs.ProblemOf(err) check for Category/Subtype, matching the pattern already used in init_interactive_test.go.
Summary
config default-asandconfig strict-modecurrently only print human-readable text with no structured output option, making them hard for AI agents to consume reliably. This PR adds a unified--output {text,json,yaml}flag to both commands' view (no-argument) branches, backed by a new shared formatter. Default (no-flag) output is unchanged.Changes
internal/output/view_format.go:ViewFormatenum +ParseViewFormat+WriteView, deliberately isolated from the existingFormat/ParseFormat/Emittermachinery (whose tests use the string"yaml"as a stand-in for "unrecognized format")--outputflag tocmd/config/default_as.go's view branch; set branch is unaffected (no-op)--outputflag tocmd/config/strict_mode.go's view branch (showStrictMode), covering both the config-mode and credential-provider-source cases; set/reset/global branches are unaffected--outputvalues return a structured validation error (exit code 2), consistent with existingcmd/configvalidation errorsconfig show/config policy show/config plugins show(already unconditional JSON) and all mutating config commands are out of scope and untouchedTest Plan
go build ./...passedgo test ./internal/output/... ./cmd/config/...passed, including byte-exact regression assertions for unflagged outputconfig default-as --output json,config strict-mode --output yaml,config default-as --output xml(confirms invalid-value error),config default-as bot --output json(confirms no-op on set path)Related Issues
N/A
Summary by CodeRabbit
--outputsupport forconfig default-asandconfig strict-modeview output, withtext,json, andyaml.--outputis omitted, output defaults totext.strict-modeview output now consistently includes the active setting source and resolved value across output formats.text/json/yamland to confirm invalid--outputvalues return proper validation errors.