Reference: A CLI Tool Shipped to Users
A reference for user-facing CLI tools: clap 4 for parsing, structured errors, cross-platform builds with cargo-dist, and support-friendly --version output with git SHA and Rust toolchain metadata.
Search across all documentation pages
A reference for user-facing CLI tools: clap 4 for parsing, structured errors, cross-platform builds with cargo-dist, and support-friendly --version output with git SHA and Rust toolchain metadata.
Quick-reference recipe card - copy-paste ready.
acme-cli/
src/
main.rs
cmd/ # subcommands
error.rs
tests/
cli_integration.rs
dist.toml # cargo-dist manifest
CHANGELOG.mdWhen to reach for this:
use clap::{Parser, Subcommand};
use std::process::ExitCode;
#[derive(Parser)]
#[command(name = "acme", version, about = "Acme operator CLI")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Export tenant data to JSON
Export { tenant_id: String, #[arg(long)] out: std::path::PathBuf },
}
fn main() -> ExitCode {
let cli = Cli::parse();
match run(cli) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("error: {e}");
e.exit_code()
}
}
}
fn run(cli: Cli) -> Result<(), AppError> {
match cli.command {
Commands::Export { tenant_id, out } => export(&tenant_id, &out)?,
}
Ok(())
}# cargo-dist release (simplified)
cargo dist build --artifacts=archives
cargo dist publish --tag v1.2.0// tests/cli_integration.rs
use assert_cmd::Command;
#[test]
fn export_requires_tenant() {
Command::cargo_bin("acme").unwrap()
.arg("export")
.assert()
.failure();
}--format json for automation.acme --version includes semver, SHA, rustc version for ticket correlation.
Result everywhere in run().strip, LTO, avoid unused features.assert_cmd smoke tests in CI.
| Alternative | Use When | Don't Use When |
|---|---|---|
| xtask crate | Repo maintainer tasks only | End-user product |
| Shell wrapper | Legacy install path | Complex validation needed |
| TUI (ratatui) | Interactive ops | CI automation primary |
State in README; align with enterprise LTS if applicable.
Separate from server API; document signature verification.
Test on CI matrix; path and line ending edge cases.
clap env overrides; document precedence in --help.
Opt-in only; document in privacy notice.
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 19, 2026