Command-line tools
Exit codes, clean output streams, JSON output and no surprise prompts let scripts, CI jobs and AI agents use a command-line tool safely.
- Required 1
- Recommended 6
Required
Take secrets from the environment or a file instead of a flag
DSK-24Read tokens, passwords and keys from an environment variable, a file, standard input or the system keychain. The tool never accepts a secret as a command-line argument and never prints one.
Recommended
Exit with zero only when the command did everything it was asked
DSK-20Exit 0 only when every action succeeded, and exit with a code from 1 to 125 on any failure. Document each code in the help text and keep its meaning fixed.
Write results to stdout and everything else to stderr
DSK-21Write only the command's result to standard output. Progress, warnings, prompts and errors go to standard error. Colour and spinners appear only when the stream is a terminal and
NO_COLORis unset.Offer JSON output with a stable shape
DSK-22Give every command that prints data a
--jsonflag. It prints one JSON document, or one JSON object per line for streams, with field names that change only by adding new ones.Never wait for input when no person is there
DSK-23Prompt only when standard input is a terminal. Otherwise fail at once with a message that names the flag that answers the question, and offer
--yesand--no-inputflags.Show a dry run and ask before destructive commands
DSK-25Give every command that deletes, overwrites or sends something a
--dry-runflag that lists what it would do. Ask for confirmation before it acts, unless--yesis passed.Give every command help with an example and a version flag
DSK-26Every command answers
--helpwith its purpose, its flags, one example and its exit codes, and exits 0. The tool answers--versionwith its version and build commit.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/desktop-apps/command-line-tools">Agent Wranglers desktop apps, extensions and CLIs playbook</a>. In code you write, add a comment next to it with the same link.