Skip to content

feat: add --json flag to list command#2

Closed
glitch418x wants to merge 4 commits intomainfrom
feat/list-json-coderabbit
Closed

feat: add --json flag to list command#2
glitch418x wants to merge 4 commits intomainfrom
feat/list-json-coderabbit

Conversation

@glitch418x
Copy link
Contributor

@glitch418x glitch418x commented Feb 18, 2026

Summary

Adds a --json flag to the list subcommand for machine-readable output.

Changes

  • Add serde + serde_json dependencies
  • Derive Serialize on TccEntry and sub-types
  • Add --json bool flag to List command — outputs a JSON array when set, existing table output unchanged
  • --compact conflicts with --json (clap enforces, errors if both passed)
  • Graceful error handling on serialization failure (stderr + exit 1)
  • Integration tests that run unconditionally without a live TCC DB

Usage

tccutil-rs list --json
tccutil-rs list --json --client Accessibility

Summary by CodeRabbit

  • New Features
    • Added JSON output support to the list command via --json flag for integration with JSON tools and automation
    • List entries now output in structured JSON format for programmatic consumption
    • Made --json and --compact flags mutually exclusive to prevent conflicting output formats

glitch418x and others added 4 commits February 18, 2026 09:28
Adds serde/serde_json dependencies and a --json flag to the list
subcommand. When passed, entries serialize as a JSON array instead
of the human-readable table. Includes integration tests for valid
JSON output and filtered JSON output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ith json, test robustness

- Remove redundant serde_json from [dev-dependencies] (already in [dependencies])
- Add conflicts_with("json") to --compact arg so clap errors on mutual use
- Restructure list_json_outputs_valid_json_array to assert unconditionally
- Add list_json_service_filter_returns_valid_structure test
- Add list_compact_and_json_conflict integration + unit tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both list_json_outputs_valid_json_array and
list_json_with_client_filter_only_contains_matching_entries had
field/filter assertions inside for-loops over DB entries. When the
TCC DB is empty (always the case in CI), these loops execute zero
iterations, giving false confidence.

Fix:
- Fields test: add unconditional mock-entry field check that verifies
  the EXPECTED_JSON_FIELDS list matches the TccEntry serialization
  contract, independent of DB contents.
- Filter test: add unconditional assertion that filtering by a
  guaranteed-nonexistent client produces a valid empty JSON array,
  exercising the filter code path even on empty DBs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…pect panic

- Replace tautological mock JSON schema test with actual TccEntry
  serialization check (catches field additions/removals/renames)
- Add lib.rs to expose TccEntry to integration tests
- Strengthen filter test with explicit object/field assertions
- Replace .expect() panic on serialization failure with stderr + exit(1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@glitch418x glitch418x self-assigned this Feb 18, 2026
@glitch418x glitch418x requested a review from altaywtf February 18, 2026 06:54
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds JSON output support to the list command by introducing serde dependencies, converting the crate to a library with public module exports, adding a mutually-exclusive --json flag to the List command, implementing serialization for list entries, and providing comprehensive test coverage for the new functionality.

Changes

Cohort / File(s) Summary
Configuration & Library Setup
Cargo.toml, src/lib.rs
Adds serde and serde_json dependencies; declares library target "tccutil_rs" and creates public module re-export for tcc.
Serialization Support
src/tcc.rs
Updates TccEntry struct to derive Serialize trait alongside existing Debug derivation for JSON serialization capability.
CLI JSON Feature
src/main.rs
Imports from new library path; adds --json flag to List subcommand with conflict constraint against --compact; implements conditional JSON serialization or table output based on flag; updates command handling and imports to use TccError.
Integration Tests
tests/integration.rs
Adds 158 lines of comprehensive test coverage for JSON output validation, filtering behavior, field presence checks, flag conflict detection, and empty result handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A JSON wish, a flag so neat,
List outputs make serialization sweet,
Pretty-printed data, flowing free,
Hops and hops of structured glee!

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/list-json-coderabbit

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

@glitch418x
Copy link
Contributor Author

Closing — will open fresh with clean single commit.

@glitch418x glitch418x closed this Feb 18, 2026
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