Well-designed command-line tools treat the terminal both as a human interface and as a programmable API. Following standard stream and exit conventions prevents brittle shell wrappers.
Standard Streams Contract
Always separate primary payload data from human-readable status messages:
stdout(fd 1): Reserved strictly for primary machine-readable or pipeable output (JSON, CSV, file paths, or transformed text).stderr(fd 2): Used for progress indicators, warnings, error diagnostics, and interactive prompts.
# Clean separation lets users pipe stdout safely while still seeing errors
crafttool export --format json | jq '.items[] | .id'
Deterministic Exit Codes
Scripts rely on exit status codes rather than parsing error strings:
| Code | Meaning | Typical Trigger |
|---|---|---|
0 |
Success | Command completed normally |
1 |
General Error | Unhandled runtime or I/O failure |
2 |
Usage Error | Invalid CLI flag, missing argument, or bad config syntax |
64–78 |
sysexits.h |
Specialized network, permission, or data format errors |
Configuration Precedence
Resolve runtime settings in a strict, documented order from highest to lowest priority:
- Explicit command-line flags (
--timeout 30) - Environment variables (
CRAFTTOOL_TIMEOUT=30) - Local project configuration file (
./crafttool.toml) - Global user configuration (
~/.config/crafttool/config.toml) - Built-in safe defaults
#cli
#unix
#systems
#developer-tools