CLI Best Practices
Rules for Rust CLIs that are discoverable, scriptable, and respectful of user time.
Search across all documentation pages
Rules for Rust CLIs that are discoverable, scriptable, and respectful of user time.
--help examples for every subcommandmyapp deploy, not myapp --deploy.--verbose / -v across all subcommands.--json or --plain flag. Machine-readable output option.--yes / --no-input for CI and scripts.lib.rs for testability.rust-toolchain.toml for reproducible builds.As many as needed, but each should be discoverable via --help.
No. Interactive only when explicitly requested or no args provided for a wizard.
clap for anything beyond a single positional argument.
Warning on use, document in help, remove in next major version.
-v once = INFO, twice = DEBUG. Log to stderr.
Env var or hidden prompt. Never argv flags.
Unit test lib.rs. Integration tests call Cli::parse_from and assert exit codes.
--version on every tool. Consistent across your CLI suite.
Default auto. Support --no-color and NO_COLOR=1.
Concise per-flag. Link to docs for long examples.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026