Skip to content

feat(cli): --json output and one exit-code table - #107

Merged
rizukirr merged 7 commits into
mainfrom
feat/cli-json-output
Nov 14, 2026
Merged

rizukirr merged 7 commits into
mainfrom
feat/cli-json-output

Conversation

@rizukirr

Copy link
Copy Markdown
Owner

Adds a global --json flag so agents and scripts can drive apic without scraping text, and gives every command one exit-code table in both modes.

With --json, every command prints exactly one JSON document on stdout: its result, or {"error": {"kind", "message"}}. Warnings stay as text on stderr.

Code Kinds When
0 success, including send getting any HTTP status
1 usage, not_initialized, error bad flags, outside a project, I/O failure, remove --json without --yes
2 not_found, ambiguous no contract or template matches the query, or several do
3 invalid a contract fails to parse or the schema, validate found failures
4 network connection refused, DNS, TLS, timeout
  • src/output.rs holds the switch, CliError { kind, message } and the table. Handlers return Result<(), CliError>, and run() is the only place that prints an error and exits.
  • read --json prints the stored contract (filtered by --status). send --json embeds a JSON body as a value, keeps text as a string and base64-encodes binary.
  • remove --json deletes only with --yes.
  • Docs: a "Machine-readable output" section in COMMAND.md, the new codes in SENDING.md, and a pointer in the README.

Behavior that changes in text mode too: read with no match exits 2 (it printed "No contract found" and exited 0), validate failures exit 3, send network errors exit 4, clap parse errors exit 1 (clap's default was 2), and config outside a project now fails.

Checked locally on Rust 1.99: cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check and cargo build --workspace all pass. CI's MSRV job is the first check on Rust 1.92.

The apic-web docs follow in a separate PR.

@rizukirr
rizukirr merged commit 5240e21 into main Nov 14, 2026
5 checks passed
@rizukirr
rizukirr deleted the feat/cli-json-output branch November 17, 2026 04:07
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