Document a command's result as three separate observations: exit status, standard output, and standard error. Explain the output mode and the meaning of an empty result. A command can print a reassuring sentence while returning failure, or succeed while reporting a warning on a separate stream.
Do not infer the complete contract from a screenshot of one successful run. The learner needs to know what can be parsed, which status means the requested work completed, and what to do with a valid result containing no items.
The compatibility matrix establishes an environment and named checks. This guide establishes the result a caller receives from a particular CLI invocation. Neither replaces the other.
Separate a public convention from your tool’s meaning
Python's sys.exit documentation describes how its argument becomes an exit status and how a non-integer argument other than None is printed to stderr with status one; None is equivalent to an exit status of zero. That explains a specific runtime mechanism. It does not define every command's business meaning or every operating system's status handling.
Read the actual tool's documentation and inspect the supported modes. Some commands deliberately use a nonzero status to indicate differences or another meaningful condition. Never rewrite such behavior into a generic “nonzero means nothing happened” rule.
Record the invocation, version, working context, expected status set, stdout grammar, stderr purpose, and whether partial results are possible. Include known limits. The caller should not need to scrape an English success phrase when a documented structured mode exists.
Avoid printing secrets or private payloads into either stream merely to make a lesson easy to debug. Output design is also a publication boundary.
Work a fictional four-outcome contract
Imagine a fictional local catalog command called sample-list. Its documented JSON mode returns a list of permitted fixture names. The following contract is invented for illustration, not an assertion about a real CLI.
| Case | Status | Stdout | Stderr |
|---|---|---|---|
| Items found | 0 | Valid JSON list | Empty |
| No matching items | 0 | Empty JSON list | Empty |
| Invalid option | 2 | Empty | Human-readable correction |
| Successful result with warning | 0 | Valid JSON list | Warning identified as nonfatal |
The empty list is a valid result under this contract. It is different from empty stdout caused by failure. The warning case still provides a parseable result, but the reader should know which warning was emitted and whether it requires action.
A different tool can choose different statuses. Publish its actual contract rather than copying these illustrative numbers into a reference page.
Protect machine output from human progress text
If the guide demonstrates JSON output, verify that stdout contains exactly the documented value or stream. A progress banner inserted before a JSON object can break a parser even though the terminal looks helpful. A colored decoration or interactive prompt can create the same problem.
Do not assume redirecting both streams into one file preserves a machine-readable format. It intentionally combines channels. Explain that consequence before showing a combined-log command, and keep the raw streams available in the acceptance record.
The Python JSON documentation notes that JSON is not a framed protocol: repeated dumps to the same file do not automatically form a valid JSON document. Use the tool's actual output grammar rather than assuming every printed JSON-looking line is one ordinary JSON file.
For interactive and noninteractive modes, record whether input is required. A tutorial command that waits for confirmation cannot be described as unattended merely because its first screen contains a result.
Test failures and pipelines deliberately
Use benign fixtures for each documented outcome and capture the streams separately. Preserve expected and observed status, bytes or decoded text, tool version, and environment. The acceptance case should parse stdout using the intended consumer, not only search for the word success.
Include an intentionally malformed output fixture to show that the parser check detects a broken contract. If the command is used in a pipeline, document how the selected shell reports pipeline status and what the reader must verify. Do not publish a universal claim based on one shell's behavior.
Distinguish process completion from task completion. A wrapper can return zero while an asynchronous task remains queued, or return an error after some work occurred. State that boundary in the specific tool's contract instead of treating the status as proof of all downstream effects.
Use the acceptance brief to require this evidence when calling a command automation-ready. A human demonstration and a machine integration need different checks.
Make the reference maintainable
Add a transcript key that distinguishes commands the user types from output the process produces. Copying a diagnostic line back into a shell is not part of the result contract. In a machine-oriented example, show the parsed value separately from commentary so readers know which bytes belong to stdout.
Record character encoding and output stability where a downstream consumer depends on them. If the tool makes no stability promise for human prose, do not create one in the article. The right answer may be to use a supported structured mode or keep a human in the loop.
Keep examples of each supported outcome beside the versioned result contract. Recheck after adding banners, warnings, new output modes, or wrapper scripts. Those changes can affect callers without changing the underlying operation.
If an earlier guide recommended parsing human prose, revise it with an accurate supported alternative where one exists. Explain any compatibility change rather than silently making old consumers wrong. A structured mode still needs schema and version boundaries.
The source worksheet can separate documented tool behavior from your proposed integration method. Publish when the learner can interpret status and output together, preserve meaningful empty results, and detect a contract failure without guessing from terminal appearance.
