
Rust Cli Clap
- 5 installs
- 5 repo stars
- Updated August 5, 2026
- bjornmelin/dev-skills
Rust-cli-clap is a Claude Code skill for building Rust command-line tools with clap, stable output contracts, and CLI tests.
About
Rust-cli-clap is a Claude Code skill for building Rust command-line tools with the clap library. It covers clap derive and builder APIs, subcommands, flags, config and env precedence, stdout/stderr contracts, JSON output, exit codes, completions, and manpages. A developer uses it when working on scriptable, terminal-friendly Rust CLIs and their tests and binary distribution.
- Builds Rust command-line tools with clap derive or builder APIs
- Designs stdout/stderr contracts, JSON output, exit codes, and completions
- Covers CLI testing with assert_cmd/trycmd and binary distribution via cargo-dist
Rust Cli Clap by the numbers
- 5 all-time installs (skills.sh)
- Ranked #93 of 121 Rust skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
rust-cli-clap capabilities & compatibility
Free; uses the Rust toolchain and cargo.
- Capabilities
- rust cli · cli testing · binary distribution
- Use cases
- api development · testing · devops
- Pricing
- Free
What rust-cli-clap says it does
Build Rust command-line tools that are predictable, scriptable, pleasant in terminals, and easy to ship.
Prefer `clap` derive for ordinary CLIs.
Design command output as an API: human output on stdout, diagnostics on stderr, deterministic `--json`/machine output where automation is expected, and stable exit codes.
npx skills add https://github.com/bjornmelin/dev-skills --skill rust-cli-clapAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 5 |
|---|---|
| repo stars | ★ 5 |
| Last updated | August 5, 2026 |
| Repository | bjornmelin/dev-skills ↗ |
What it does
Build predictable, scriptable Rust command-line tools with clap, stable output contracts, and CLI tests.
Who is it for?
Rust CLIs with clap derive or builder APIs, subcommands, config precedence, JSON output, exit codes, and completions.
Skip if: Non-CLI Rust work or terminal UIs, which route to other Rust specialist skills.
When should I use this skill?
Building command-line apps and tools, clap definitions, stdin/stdout/stderr contracts, or CLI tests and distribution.
What you get
Rust command-line tools that are predictable, scriptable, pleasant in terminals, and easy to ship.
- clap argument definitions
- stdout/stderr and JSON output contracts
- CLI tests and completions/manpages
By the numbers
- 3 reference guides (clap-parser, terminal-contracts, testing-packaging)
- 5-point operating model
Files
Rust CLI Clap
Build Rust command-line tools that are predictable, scriptable, pleasant in terminals, and easy to ship.
Operating Model
1. Discover the existing CLI contract first: Cargo.toml, src/bin, clap definitions, integration tests, snapshots, release scripts, and README examples. 2. Preserve user-facing command behavior unless the task explicitly asks for a breaking change. If behavior changes, update tests and docs in the same patch. 3. Prefer clap derive for ordinary CLIs. Use the builder API when commands are generated dynamically, hidden/unstable command surfaces need custom construction, or macros make the shape harder to read. 4. Design command output as an API: human output on stdout, diagnostics on stderr, deterministic --json/machine output where automation is expected, and stable exit codes. 5. Keep command handlers thin. Parse into typed arguments, normalize config once, then call library code that tests can exercise without spawning a process.
Reference Map
Open only the section needed for the task:
references/clap-parser-playbook.mdforclapderive/builder design, argument groups, validators, completions, and migration notes.references/terminal-contracts.mdfor stdout/stderr, color, progress, config precedence, error messages, and shell automation rules.references/testing-packaging.mdforassert_cmd,trycmd, snapshots, binaries, completions, manpages,cargo-dist, and release checks.
Defaults
- Use
clap = { features = ["derive", "env"] }when environment variables are part of the contract; otherwise avoid unused features. - Use
caminoorUtf8PathBufonly when UTF-8 paths are an explicit invariant. Otherwise keepPathBuf. - Use
anstream/anstyleorclapstyling for color-aware output; respectNO_COLOR,CLICOLOR, and non-TTY behavior. - Use
tracingfor diagnostics when the CLI has subcommands, network calls, daemon/client modes, or hidden debugging flags. - Use
thiserrorfor domain errors andmietteorcolor-eyreat the presentation boundary only when rich reports add value.
Verification
For CLI changes, prefer the smallest ladder that proves the contract:
cargo fmt --all --check
cargo test --all-targets
cargo clippy --workspace --all-targets --all-features -- -D warningsAdd focused command tests for new flags, output modes, exit codes, config precedence, and examples shown in docs. Snapshot CLI output only after normalizing volatile paths, timestamps, colors, and ordering.
display_name: Rust CLI Clap
short_description: Rust CLI and Clap command design.
default_prompt: Use $rust-cli-clap to design, implement, test, or review Rust command-line tools with clap.
policy:
allow_implicit_invocation: true
metadata:
skill_category: rust
primary_domains:
- cli
- clap
- terminal-ux
- packaging
[
{
"query": "Add a new --format json flag to our Rust CLI using clap and test the stdout contract.",
"should_trigger": true,
"reason": "Rust CLI, clap, and machine-readable output are direct matches."
},
{
"query": "Design subcommands for a cargo-style Rust binary with env overrides and shell completions.",
"should_trigger": true,
"reason": "Subcommands, env, and completions are core CLI concerns."
},
{
"query": "Review this clap derive parser for positional arguments, aliases, and error messages.",
"should_trigger": true,
"reason": "Clap parser design is the primary trigger."
},
{
"query": "Implement a ratatui dashboard with async key handling.",
"should_trigger": false,
"reason": "TUI work belongs to rust-tui-ratatui."
},
{
"query": "Secure a Tauri command exposed to the frontend.",
"should_trigger": false,
"reason": "Tauri command and capability work belongs to rust-tauri-apps."
},
{
"query": "Create an Axum middleware stack with tower layers.",
"should_trigger": false,
"reason": "Web service architecture belongs to rust-web-services."
}
]
Clap Parser Playbook
API Choice
Prefer derive for stable, statically known command trees:
- Keep the root parser small and route work through subcommand handler functions.
- Put repeated option groups in flattened structs.
- Use typed enums with
ValueEnuminstead of stringly-typed mode flags. - Use
ArgGroupfor true mutual exclusion or required-one-of contracts. - Use
value_parser!and domain parsers for validated numbers, durations, URLs, and IDs.
Use the builder API when:
- Commands are plugin-discovered or generated from runtime metadata.
- Experimental commands need hidden aliases or feature-gated registration.
- The command tree is easier to audit as data than as nested derive structs.
Avoid mixing derive and builder without a clear boundary. If a derive parser needs heavy post-processing, move that logic into a typed config normalization layer instead of hiding it in parser attributes.
Argument Design
- Prefer explicit long flags for scripts and stable short flags only for high-frequency terminal use.
- Keep positional arguments rare and obvious. Once there are multiple optional positionals, switch to named flags.
- Use
default_value_tonly when the default is part of the public contract. Otherwise compute defaults after merging config/env/CLI sources. - Use
Option<T>for absence and a separate enum for semantic modes. Avoid sentinel strings such as"auto"unlessautois a real mode. - For path inputs, accept
PathBuf; canonicalize only when required, and report the original path in user-facing errors.
Precedence Model
State precedence explicitly in docs and tests. A solid default:
1. CLI flags 2. Environment variables 3. Config files 4. Project defaults 5. Built-in defaults
Do not let clap environment values silently bypass config validation. Parse and normalize into one domain config before execution.
Help and Discovery
- Use command names as verbs:
sync,check,init,serve. - Keep help examples current by testing them.
- Generate shell completions and man pages for shipped CLIs when the distribution channel supports them.
- Hide truly internal flags with
hide = true, but avoid undocumented "support-only" behavior for public workflows.
Migration Notes
When upgrading clap, check:
- Derive attribute renames or semantic changes.
- Color/styling behavior.
- Error message snapshots.
- Shell completion output.
envfeature availability and variable naming.
Use official clap docs and changelogs for version-specific behavior before changing public parser contracts.
Terminal Contracts
Streams
- stdout is for primary command output.
- stderr is for diagnostics, progress, warnings, and trace-style information.
- JSON, NDJSON, CSV, or other machine output must be complete, deterministic, and free of human prose.
- Progress bars belong on stderr and should disable automatically when stderr is not a terminal.
Exit Codes
Keep exit codes small and documented for automation-heavy tools:
0: success1: general runtime failure2: invalid user input or usage- Additional codes only when callers can realistically branch on them.
Avoid panics for expected user errors. Convert domain failures into typed errors and a presentation layer that gives enough context to act.
Color and Formatting
- Respect
NO_COLORand non-TTY output. - Provide
--color auto|always|neverfor tools with rich output. - Use tables only for humans. Provide JSON for scripts.
- Keep terminal width responsive; avoid wrapping data in ways that break copy/paste.
Logging and Verbosity
Prefer a consistent verbosity shape:
- Default: quiet unless user action is needed.
-v/--verbose: explain major steps.-vvor tracing filter: detailed diagnostics.--quiet: suppress non-essential human output.
Do not log secrets, tokens, URLs with credentials, or full request bodies by default.
Config and Environment
Use an explicit source model. When reporting effective config, include source labels but redact secrets.
Avoid hidden environment variables. If an env var is supported, document it, test it, and include it in help when appropriate.
Testing and Packaging
Test Shape
Use direct library tests for domain behavior and process-spawning tests for CLI contracts.
Useful crates:
assert_cmdfor invoking binaries.predicatesfor stdout/stderr assertions.trycmdfor command transcript tests.instafor normalized snapshots.tempfilefor isolated filesystem state.
Test at least:
- Parser success/failure for new flags and subcommands.
- Config/env/CLI precedence.
- stdout/stderr separation.
- JSON schema or shape when machine output exists.
- Exit codes.
- Help examples that users will paste.
Snapshot Discipline
Normalize:
- absolute paths
- platform path separators when cross-platform
- timestamps
- ordering from maps, filesystems, and concurrent work
- ANSI color unless color itself is under test
Do not snapshot huge help output just because it is easy. Assert stable behavior and snapshot only the text that is intentionally public.
Distribution
For serious binaries, consider:
cargo-distfor release artifacts and installers.release-plzfor changelog/release automation.cargo-binstallsupport where appropriate.- generated completions/manpages included in packages.
Ship Cargo.lock for application binaries. Set rust-version deliberately and test the minimum supported Rust version when claiming MSRV support.
Related skills
FAQ
Should I use clap derive or the builder API?
Prefer clap derive for ordinary CLIs; use the builder API for dynamically generated commands or hidden/unstable command surfaces.
How does it design CLI output?
Human output on stdout, diagnostics on stderr, deterministic --json for automation, and stable exit codes.