Add --json to read-only pr/secret/variable commands #118

Merged
stephen merged 1 commit from fix/112-json-readonly into main 2026-06-11 00:40:56 +00:00
Owner

Adds --json to the read-only commands automation reaches for, routing each handler's already-typed struct through the existing output::print_json path that pr view / issue view use. Closes the trap where a scripter assumes the rest of pr accepts --json (because pr view does) and hits error: unexpected argument '--json' at runtime.

What's covered

  • fj pr checks --json emits the combined-status struct (state, total_count, statuses[]) — the merge-gate / "is this PR green?" query.
  • fj pr files --json and fj pr commits --json emit the per-file / per-commit arrays.
  • fj pr diff --json wraps the text as { "diff": "..." } rather than rejecting the flag; the decision is recorded in the subcommand help.
  • fj secret list --json and fj variable list --json emit name / created_at (or data) arrays for config diffing.
  • The global --json-fields projection works against each new output, since they all flow through print_json.

Implementation notes

The inspect subcommands moved from the shared SimpleArgs to a new InspectArgs that carries --json, so the mutating siblings (ready / close / reopen) keep a clean argument surface. secret list and variable list share SecretListArgs, so a single flag covers both. The shared output::print_json helper is reused untouched.

Tests

  • A regression test walks the whole clap command tree and asserts every view / list / inspect leaf either accepts --json or is explicitly allow-listed as text-only, so the surface cannot silently regress. The handful of pre-existing local/config listings (auth list, alias list, config list, extension list, instances list, auth status) are allow-listed with reasons.
  • Wiremock tests cover each new JSON path end to end and assert both the serialized shape and a --json-fields projection over it (including dotted-path and array projection).

Gates: cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings, cargo test --all (447 passing) all green.

Fixes rasterstate/fj#112

Adds `--json` to the read-only commands automation reaches for, routing each handler's already-typed struct through the existing `output::print_json` path that `pr view` / `issue view` use. Closes the trap where a scripter assumes the rest of `pr` accepts `--json` (because `pr view` does) and hits `error: unexpected argument '--json'` at runtime. ## What's covered - `fj pr checks --json` emits the combined-status struct (`state`, `total_count`, `statuses[]`) — the merge-gate / "is this PR green?" query. - `fj pr files --json` and `fj pr commits --json` emit the per-file / per-commit arrays. - `fj pr diff --json` wraps the text as `{ "diff": "..." }` rather than rejecting the flag; the decision is recorded in the subcommand help. - `fj secret list --json` and `fj variable list --json` emit `name` / `created_at` (or `data`) arrays for config diffing. - The global `--json-fields` projection works against each new output, since they all flow through `print_json`. ## Implementation notes The inspect subcommands moved from the shared `SimpleArgs` to a new `InspectArgs` that carries `--json`, so the mutating siblings (`ready` / `close` / `reopen`) keep a clean argument surface. `secret list` and `variable list` share `SecretListArgs`, so a single flag covers both. The shared `output::print_json` helper is reused untouched. ## Tests - A regression test walks the whole clap command tree and asserts every `view` / `list` / inspect leaf either accepts `--json` or is explicitly allow-listed as text-only, so the surface cannot silently regress. The handful of pre-existing local/config listings (`auth list`, `alias list`, `config list`, `extension list`, `instances list`, `auth status`) are allow-listed with reasons. - Wiremock tests cover each new JSON path end to end and assert both the serialized shape and a `--json-fields` projection over it (including dotted-path and array projection). Gates: `cargo fmt --check`, `cargo clippy --all-targets --all-features -- -D warnings`, `cargo test --all` (447 passing) all green. Fixes rasterstate/fj#112
Add --json to read-only pr/secret/variable commands
All checks were successful
ci / check (pull_request) Successful in 9m41s
ci / coverage (pull_request) Successful in 1m49s
ci / live-e2e (pull_request) Successful in 1m43s
28e572c759
The read-only inspect surface (pr diff/commits/files/checks, secret list,
variable list) built structured data in memory and only ever flattened it
to a table, so automation hit `error: unexpected argument '--json'` even
though pr view / issue view accept it. Route each handler's already-typed
struct through the existing output::print_json path so --json and the
global --json-fields projection work uniformly.

pr diff is text, so --json wraps it as `{ "diff": "..." }` rather than
rejecting the flag; the decision is recorded in the subcommand help.

A new regression test walks the clap tree and asserts every view/list/
inspect leaf either accepts --json or is explicitly allow-listed as
text-only, so the surface cannot silently regress. Wiremock tests cover
each new JSON path and its field projection.

Fixes rasterstate/fj#112
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rasterstate/fj!118
No description provided.