feat(cli): --json flag, pr diff/checkout, commit view, milestone create
CLI gap audit follow-ups (closes #10, #11, #12, #13, #17). All work is
CLI-only — no new server endpoints required for any of these.
* **--json** (#10): top-level global flag. When passed, every list/view
command short-circuits the table renderer and pretty-prints the raw
server JSON. Implemented as a process-global atomic so the flag
propagates without threading through every fn signature. Wired into
the most-used surfaces: pr list/view, issue list/view, epic list/view,
ci list/view, milestone list/view, repo view, branch list, commit list.
Other list/view commands (label, ssh-key, requirement, release, deploy,
agent, board, runner) remain table-only — follow-up.
* **anvil pr diff <num>** (#11): resolves the PR via existing
`GET /pulls/:n` to get base/head branches, runs `git fetch origin
base head`, then `git diff origin/base...origin/head`. --name-only
flag for file list. --remote to override. Pure local git wrapper.
* **anvil pr checkout <num>** (#12): resolves PR head_branch, refuses
to clobber uncommitted changes (mirrors `gh pr checkout`),
`git fetch` + `git checkout -B <head> origin/<head>`. Pure local
git wrapper.
* **anvil commit view <sha>** (#17): wraps `git show` (with --stat
--no-patch by default; --diff to include patch). Pure local git.
* **anvil milestone create** (#13): server already has `POST /milestones`,
just adds the CLI verb. The other CRUD verbs (edit/close/reopen/delete)
need server endpoints and are blocked. The duplicate
`anvil issue milestones` and `anvil issue create-milestone` now emit
deprecation warnings and delegate to the milestone command.
Tests:
* src/output.rs: roundtrip tests for set_json_mode/is_json + smoke
test for print_json.
* src/commands/pr.rs: clap parsing for `pr diff` and `pr checkout`.
* src/commands/commit.rs: clap parsing for `commit view`.
* src/commands/milestone.rs: clap parsing for `milestone create`.
39/39 cargo tests pass. cargo clippy --all-targets -D warnings clean.
cargo fmt clean.
Verified live against production:
- `anvil pr list fangorn/anvil-cli --json` returns valid JSON
- `anvil pr view 13 --repo fangorn/anvil-cli --json` returns valid JSON
- `anvil milestone --help` shows new `create` verb
- `anvil pr --help` shows new `diff` and `checkout` verbs
- `anvil commit --help` shows new `view` verb
Blocked on server work (filed separately):
#14 anvil pr rebase — needs POST /pulls/:n/rebase
#15 anvil branch ... — needs branch CRUD + protection endpoints
#16 anvil status/inbox — needs aggregation endpoint
Closes #10, #11, #12, #13, #17
SHA:
0430ea2cdebfb93074aa52a637b5dbd2b27d00f2
Author:
CI <ci@anvil.test>
Date:
2026-05-09 03:52
Parents:
337a754
10 files changed
+511
-56
| Type | ||
|---|---|---|
|
|
src/output.rs | +64 −0 |
|
||