Rust CLI
Rule
Build CLIs that are predictable for humans and scripts. Keep parsing and process exit at the
edge; put core logic in testable library modules.
Hard Stops
Ask before:
- Adding Clap, changing public flags/subcommands/output formats/exit codes, or generating
completions into user directories.
- Performing destructive actions, reading secrets, modifying global config, or adding
interactive prompts.
- Adding color/progress/rendering libraries when plain output is sufficient.
Defaults
- Use
clap derive for non-trivial CLIs when approved; manual std parsing is acceptable for
tiny internal tools.
- Use
main only for parse/config/logging/bootstrap and process exit.
- Return
Result from testable command functions; convert errors to user-facing messages at
the edge.
- Use stdout for requested output; stderr for diagnostics/progress.
- Use stable exit codes:
0 success, 1 runtime failure, 2 usage error unless documented
otherwise.
- Integrate
tracing/logging via explicit flags only when observability is in scope.
Testing
Test core command functions directly. Use assert_cmd and predicates only when approved or
already present for binary-level tests. Assert args, env vars, stdin/stdout/stderr, exit
codes, config precedence, and side effects.
Workflow
- Define command contract: args, flags, env vars, stdin/stdout/stderr, exit codes.
- Choose manual parsing or Clap based on real complexity.
- Keep business logic outside parsing.
- Add tests for success, usage errors, runtime failures, and output stability.
- Run CLI tests, full tests, Clippy, and
just check.
Completion
Report command contract, flags/env vars, exit codes, dependency choices, tests, and
validation.
Source: nyquistwilder/personal-pi — distributed by TomeVault.
1---2name: rust-cli3description: Greenfield Rust CLI workflow for clap command structure, args, environment integration, stdin/stdout/stderr discipline, exit codes, completions, config integration, and CLI tests. Use when this capability is needed.4---56# Rust CLI78## Rule910Build CLIs that are predictable for humans and scripts. Keep parsing and process exit at the11edge; put core logic in testable library modules.1213## Hard Stops1415Ask before:1617- Adding Clap, changing public flags/subcommands/output formats/exit codes, or generating18 completions into user directories.19- Performing destructive actions, reading secrets, modifying global config, or adding20 interactive prompts.21- Adding color/progress/rendering libraries when plain output is sufficient.2223## Defaults2425- Use `clap` derive for non-trivial CLIs when approved; manual std parsing is acceptable for26 tiny internal tools.27- Use `main` only for parse/config/logging/bootstrap and process exit.28- Return `Result` from testable command functions; convert errors to user-facing messages at29 the edge.30- Use stdout for requested output; stderr for diagnostics/progress.31- Use stable exit codes: `0` success, `1` runtime failure, `2` usage error unless documented32 otherwise.33- Integrate `tracing`/logging via explicit flags only when observability is in scope.3435## Testing3637Test core command functions directly. Use `assert_cmd` and `predicates` only when approved or38already present for binary-level tests. Assert args, env vars, stdin/stdout/stderr, exit39codes, config precedence, and side effects.4041## Workflow42431. Define command contract: args, flags, env vars, stdin/stdout/stderr, exit codes.442. Choose manual parsing or Clap based on real complexity.453. Keep business logic outside parsing.464. Add tests for success, usage errors, runtime failures, and output stability.475. Run CLI tests, full tests, Clippy, and `just check`.4849## Completion5051Report command contract, flags/env vars, exit codes, dependency choices, tests, and52validation.5354---55> Source: [nyquistwilder/personal-pi](https://github.com/nyquistwilder/personal-pi) — distributed by [TomeVault](https://tomevault.io).56<!-- tomevault:4.0:skill_md:2026-06-16 -->