Skip to content

feat: add --json output mode for CLI results#6

Merged
altaywtf merged 1 commit intomainfrom
feat/json-output-mode
Feb 20, 2026
Merged

feat: add --json output mode for CLI results#6
altaywtf merged 1 commit intomainfrom
feat/json-output-mode

Conversation

@glitch418x
Copy link
Contributor

@glitch418x glitch418x commented Feb 20, 2026

Summary

  • add global --json / -j output mode for machine-readable responses
  • keep default human-readable output unchanged
  • add integration coverage for JSON success and error output shapes

Validation

  • cargo fmt --check
  • cargo clippy -- -D warnings
  • cargo test

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a --json/-j flag for JSON output mode across all commands, enabling structured programmatic consumption of command results and error information.
  • Tests

    • Added comprehensive JSON mode testing to validate output structure for list, grant, and services commands.

@glitch418x glitch418x self-assigned this Feb 20, 2026
@glitch418x glitch418x requested a review from altaywtf February 20, 2026 18:54
@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

The changes introduce a global --json/-j flag for JSON output mode, adding structured JSON error handling and data emission across all commands. A new warning suppression mechanism is implemented in the database layer to silence non-fatal warnings when in JSON mode. Integration tests validate JSON output validity.

Changes

Cohort / File(s) Summary
JSON Output Infrastructure
src/main.rs
Introduces global --json flag, JSON mode detection, and comprehensive JSON helpers (json_escape, emit_json, emit_json_error, emit_json_success). Adds JSON data formatters for list, services, and info commands. Implements TccError JSON handling with error_kind() mapping. Modifies command execution paths to conditionally emit structured JSON or human-readable output.
Warning Suppression
src/tcc.rs
Adds suppress_warnings: bool field to TccDb struct with public setter method. Threads suppression flag through read/write operations, making warning output conditional in list, grant, revoke, enable, disable, and reset flows.
JSON Mode Tests
tests/integration.rs
Adds assert_basic_json_shape() helper and three new tests validating JSON mode: services_json_mode_returns_valid_json, list_json_mode_returns_valid_json, and grant_json_mode_failure_has_error_shape. Tests verify JSON structure and field presence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 A flag called --json now hops through the code,
Warnings suppressed on the structured output road,
Errors in JSON, no stderr cries,
Data flows neatly in format disguise,
The CLI speaks JSON—how the times fly! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature being added: a --json output mode for CLI results, which aligns perfectly with the primary objective and changes throughout the changeset.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/json-output-mode

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

Copy link

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@src/main.rs`:
- Around line 517-519: The pre-parse JSON detector in wants_json_from_args only
checks for an exact "-j" and misses bundled short flags like "-uj"; update
wants_json_from_args to return true when any arg is "--json" or when an arg is a
short-flag bundle (starts with a single '-' but not '--') and its characters
after the first include 'j'. Implement this by iterating env::args(), checking
arg == "--json" first, then for args that start with '-' and not with "--" use
the characters after the leading '-' and return true if any is 'j' (preserving
the existing exact "-j" behavior as a subset).

@altaywtf altaywtf merged commit 309d6cc into main Feb 20, 2026
2 checks passed
@altaywtf altaywtf deleted the feat/json-output-mode branch February 20, 2026 19:05
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.

2 participants