Skip to content

feat: add JSON output format#26

Open
robertsinke wants to merge 1 commit into
JulienTant:mainfrom
robertsinke:add-json-output
Open

feat: add JSON output format#26
robertsinke wants to merge 1 commit into
JulienTant:mainfrom
robertsinke:add-json-output

Conversation

@robertsinke

@robertsinke robertsinke commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Adds a machine-readable JSON output mode via the global --format flag while preserving existing text output as the default.

Supported commands:

  • blogwatcher-cli add ... --format json
  • blogwatcher-cli remove ... --yes --format json
  • blogwatcher-cli blogs --format json
  • blogwatcher-cli scan --format json
  • blogwatcher-cli articles --format json
  • blogwatcher-cli read <id> --format json
  • blogwatcher-cli unread <id> --format json
  • blogwatcher-cli read-all --yes --format json
  • blogwatcher-cli import subscriptions.opml --format json

This makes the CLI easier to use from scripts and agent/tool integrations without parsing human-oriented terminal output.

Notes

  • Default behavior remains unchanged: --format text is the default.
  • BLOGWATCHER_FORMAT=json works via the existing viper env binding.
  • Invalid formats fail early with a clear error.
  • Commands that prompt for confirmation in text mode (remove, read-all) require --yes in JSON mode to avoid interactive/non-JSON prompts.
  • Docs and the bundled skill mention JSON output for automation.

Testing

go test ./...

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds machine-readable JSON output to the CLI tool. A new persistent --format flag controls output as text (default) or JSON. When JSON mode is enabled, the blogs, scan, and articles commands return structured JSON responses instead of human-readable text. The feature includes validation, configuration binding, and comprehensive end-to-end tests.

Changes

JSON Output Feature

Layer / File(s) Summary
CLI Format Flag and Configuration
internal/cli/root.go
Add --format persistent flag to control output and validate the format value during config initialization.
Output Format Serialization Infrastructure
internal/cli/output.go
Define output structs for blogs, articles, and scan results with JSON tags. Implement validation helpers, JSON encoder, and transformation functions to convert internal models into JSON-serializable shapes.
Command Output Integration
internal/cli/commands.go
Integrate JSON output into blogs, scan, and articles commands by checking JSON mode and returning structured JSON responses. Suppress human-readable console output when JSON mode is active.
End-to-End Tests
e2e/e2e_test.go
Test JSON output structure and field validation for blogs, scan, and articles across flag and environment variable modes. Verify that unsupported format values fail with expected error messages.
User Documentation
README.md, skills/SKILL.md
Document JSON output feature with CLI examples, environment variable support via BLOGWATCHER_FORMAT, and guidance for agent/automation usage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops with joy at JSON's birth,
Structured data proves its worth!
Blogs and scans now speak machine,
The cleanest output ever seen. 🎉

🚥 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 and specifically summarizes the main change: adding JSON output format support to the CLI.
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.
Description check ✅ Passed The PR description covers the main objective (JSON output mode), lists supported commands, explains default behavior, testing approach, and relevant notes. All key information is present and well-structured.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant