CLI Contract (Stable)

This document defines the stable, fully implemented, backward-compatible CLI contract for jq-lite.

All behaviors documented here are guaranteed, test-backed, and actively enforced by automated tests. Breaking changes require a major version bump.

Goals

Compatibility Guarantee

Exit Codes

jq-lite returns one of the following exit codes:

| Code | Meaning | | ---- | ----------------------------------------------------------------------- | | 0 | Success | | 1 | -e/--exit-status specified and result is false, null, or empty output | | 2 | Compile error (filter parse error) | | 3 | Runtime error (evaluation failed) | | 4 | Input error (failed to read or decode input) | | 5 | Usage error (invalid CLI arguments, invalid --argjson, etc.) |

stdout / stderr Rules

stdout

stderr

| Category | Prefix | Exit Code | | -------- | ----------- | --------- | | Compile | [COMPILE] | 2 | | Runtime | [RUNTIME] | 3 | | Input | [INPUT] | 4 | | Usage | [USAGE] | 5 |

Example:


[COMPILE] unexpected token at …
[RUNTIME] type mismatch at …
[INPUT] failed to parse JSON input: …
[USAGE] invalid JSON for --argjson x

Compile Before Input Parsing

Filter compilation MUST occur before input parsing.

If both the filter and the input are invalid, jq-lite MUST report a compile error, not an input error:

printf '{broken}\n' | jq-lite '.[ '
# stderr: [COMPILE] …
# exit: 2

Input parsing errors MUST NOT mask compile errors.

Truthiness (-e/--exit-status)

When -e/--exit-status is specified:

| Result | Exit | | -------------------- | ---- | | truthy | 0 | | false / null / empty | 1 |

Truthiness rules (jq-style):

Argument Semantics

--arg name value

--argjson name json

--argfile name file

-n / --null-input

When -n is specified:

Example:

jq-lite -n 'null'
# stdout: null
# exit: 0

Broken Pipe (SIGPIPE / EPIPE)

When downstream closes the pipe early:

jq-lite '.[]' | head

Rationale: This frequently occurs in pipelines and must not break scripts or CI.

Examples

Compile Error

jq-lite '.[ '
# stderr: [COMPILE] …
# exit: 2

Runtime Error

printf '{"x":"a"}\n' | jq-lite '.x + 1'
# stderr: [RUNTIME] …
# exit: 3

Input Error

printf '{broken}\n' | jq-lite '.'
# stderr: [INPUT] …
# exit: 4

-e falsey Result

printf 'false\n' | jq-lite -e '.'
# stdout: false
# exit: 1

Resolved Contract Items

The following contract items are fully implemented and covered by tests:

Test-backed Guarantee

This contract is enforced by automated tests. Any violation will fail CI:

prove -lv t/cli_contract.t

Summary