Skip to content

feat: add --output text/json/yaml to config view commands#2017

Open
gengyi1207-bit wants to merge 6 commits into
larksuite:mainfrom
gengyi1207-bit:feat/config-output-format
Open

feat: add --output text/json/yaml to config view commands#2017
gengyi1207-bit wants to merge 6 commits into
larksuite:mainfrom
gengyi1207-bit:feat/config-output-format

Conversation

@gengyi1207-bit

@gengyi1207-bit gengyi1207-bit commented Jul 22, 2026

Copy link
Copy Markdown

Summary

config default-as and config strict-mode currently 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

  • Add internal/output/view_format.go: ViewFormat enum + ParseViewFormat + WriteView, deliberately isolated from the existing Format/ParseFormat/Emitter machinery (whose tests use the string "yaml" as a stand-in for "unrecognized format")
  • Add --output flag to cmd/config/default_as.go's view branch; set branch is unaffected (no-op)
  • Add --output flag to cmd/config/strict_mode.go's view branch (showStrictMode), covering both the config-mode and credential-provider-source cases; set/reset/global branches are unaffected
  • Invalid --output values return a structured validation error (exit code 2), consistent with existing cmd/config validation errors
  • config show / config policy show / config plugins show (already unconditional JSON) and all mutating config commands are out of scope and untouched

Test Plan

  • go build ./... passed
  • go test ./internal/output/... ./cmd/config/... passed, including byte-exact regression assertions for unflagged output
  • Manual verification: config 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

  • New Features
    • Added formatted --output support for config default-as and config strict-mode view output, with text, json, and yaml.
    • When --output is omitted, output defaults to text.
  • Bug Fixes
    • strict-mode view output now consistently includes the active setting source and resolved value across output formats.
  • Tests
    • Expanded CLI and unit tests to verify exact rendering for text/json/yaml and to confirm invalid --output values return proper validation errors.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31de5e96-4b75-479a-9a16-8137cad74351

📥 Commits

Reviewing files that changed from the base of the PR and between 847183a and 1416674.

📒 Files selected for processing (3)
  • cmd/config/default_as_test.go
  • cmd/config/strict_mode_test.go
  • internal/output/view_format_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • cmd/config/strict_mode_test.go
  • cmd/config/default_as_test.go
  • internal/output/view_format_test.go

📝 Walkthrough

Walkthrough

Configuration view output now supports text, JSON, and YAML formats through shared parsing and rendering helpers. The default-as and strict-mode commands expose --output, preserve text behavior, and add serialization and validation coverage.

Changes

Configuration view output

Layer / File(s) Summary
View format parsing and rendering
internal/output/view_format.go, internal/output/view_format_test.go
Adds supported view formats, output validation, shared text/JSON/YAML rendering, and serialization tests.
Default-as formatted view
cmd/config/default_as.go, cmd/config/default_as_test.go
Adds --output support, normalizes empty values to auto, and tests formatted output, invalid formats, and set behavior.
Strict-mode formatted view
cmd/config/strict_mode.go, cmd/config/strict_mode_test.go
Adds formatted mode and source output, credential-provider resolution coverage, exact output assertions, and invalid-format tests.

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
Loading

Suggested labels: feature

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding structured output modes to config view commands.
Description check ✅ Passed The description matches the template and includes a solid summary, changes, test plan, and related issues section.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between af8507e and 0319ed1.

📒 Files selected for processing (6)
  • cmd/config/default_as.go
  • cmd/config/default_as_test.go
  • cmd/config/strict_mode.go
  • cmd/config/strict_mode_test.go
  • internal/output/view_format.go
  • internal/output/view_format_test.go

Comment thread internal/output/view_format.go Outdated
Comment thread internal/output/view_format.go Outdated
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).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0319ed1 and 847183a.

📒 Files selected for processing (4)
  • cmd/config/default_as_test.go
  • cmd/config/strict_mode_test.go
  • internal/output/view_format.go
  • internal/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

Comment thread cmd/config/default_as_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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant