Rust CLI taste — Claude and Claude.ai prompt: rules for Rust CLIs
A prompt that tells the model how to write a Rust command-line tool: argument parsing, error handling, output streams, tests.
Open on GitHubWhat Rust CLI taste does
This prompt is a list of nineteen rules for building a Rust CLI. Arguments get parsed with clap and the derive API, and doc comments become the help text. main returns anyhow::Result, and every fallible step carries .context(). Library error types use thiserror; anyhow stays in the binary.
The crate splits into a thin main.rs and a lib.rs that holds the real logic, so the logic can be tested. Normal output goes to stdout, while logs, progress and errors go to stderr. A --json flag gives machine-readable output through serde, tracing runs with an env filter driven by -v flags and a RUST_LOG override, and colors are dropped when stdout is not a terminal or NO_COLOR is set. Progress bars via indicatif are reserved for operations longer than about a second. Exit codes are distinct and documented instead of always 1.
Config is read in order: flags, then environment variables, then a TOML file, with paths found through the directories crate. End-to-end tests use assert_cmd, snapshots use insta. The prompt advises against async and tokio unless the tool really does concurrent network work. The build side covers clap_complete and clap_mangen for completions and a man page, cargo-dist for prebuilt Linux, macOS and Windows binaries from GitHub Actions, clippy with warnings denied and cargo fmt --check in CI. One rule handles Ctrl+C through the ctrlc crate so no half-written files are left behind.
What it helps with
- parse CLI arguments and pull help text from doc comments
- attach context to every fallible step instead of a bare
? - split the crate into a thin
main.rsand a testablelib.rs - emit machine-readable output behind a
--jsonflag - return distinct exit codes instead of always 1
Example prompts for the agent
- Write a Rust CLI following Rust CLI taste: clap with derive, anyhow in main, thiserror in the library.
- Parse the arguments with clap and add
.context()to every step that can fail. - Add a
--jsonflag with serde and disable colors when stdout is not a terminal.
How to install Rust CLI taste
How to use
Paste the text at the start of a chat or into project instructions
Manually: put the files in place
.claude/commands/prompts.csv.mdQuestions about Rust CLI taste
How do I install Rust CLI taste in Claude?
There is no install command: paste the prompt into the chat as a message or save it in your custom instructions.
What does Rust CLI taste do?
It sets the rules the model follows when writing a Rust command-line tool: clap, anyhow and thiserror, output split across streams, tests with assert_cmd and insta.
Do I need tokio for a tool built with this prompt?
The prompt advises skipping async and tokio unless the tool really does concurrent network work.
Source text
prompts.csv · CC0-1.0
# Rust CLI taste - Parse arguments with clap using the derive API and doc comments as help text. Confidence: 0.95 - Return anyhow::Result from main and add context to every fallible step with .context(). Confidence: 0.90 - Define library error types with thiserror and keep anyhow in the binary only. Confidence: 0.85 - Split the crate into a thin main.rs and a lib.rs that holds the real logic for testing. Confidence: 0.85 - Write normal output to stdout and logs, progress and errors to stderr. Confidence: 0.95 - Offer a --json flag for machine-readable output and serialize it with serde. Confidence: 0.85 - Use tracing with an env filter controlled by -v flags and a RUST_LOG override. Confidence: 0.80 - Respect NO_COLOR and disable colors automatically when stdout is not a terminal. Confidence: 0.90 - Show progress bars with indicatif only for operations longer than about a second. Confidence: 0.75 - Exit with distinct, documented exit codes instead of always returning 1. Confidence: 0.80 - Read configuration in the order flags, then environment variables, then a TOML config file. Confidence: 0.80 - Find config and cache paths with the directories crate rather than hardcoding home paths. Confidence: 0.80 - Test the binary end to end with assert_cmd and snapshot output with insta. Confidence: 0.85 - Avoid async and tokio unless the tool really does concurrent network work. Confidence: 0.75 - Generate shell completions and a man page with clap_complete and clap_mangen at build time. Confidence: 0.75 - Ship prebuilt binaries for Linux, macOS and Windows with cargo-dist from GitHub Actions. Confidence: 0.80 - Run cargo clippy with warnings denied and cargo fmt --check in CI. Confidence: 0.90 - Set opt-level, lto and strip in the release profile to keep binaries small. Confidence: 0.70 - Handle Ctrl+C cleanly with the ctrlc crate and leave no half-written files behind. Confidence: 0.80
© f · CC0-1.0 · f/prompts.chat