This walks you through building production-grade Rust CLIs with Clap's derive macros. It covers the full stack: subcommands with global flags, config layering (CLI over env over file), proper exit codes, and testing your binary surface with assert_cmd. The progressive disclosure is solid, token estimate looks right at 4500 for the full context. Most valuable for the subcommand patterns and the config merge precedence rules, which are easy to get wrong. Skips the builder API entirely and goes straight to derive, which is the right call for 2024. If you're past "hello world" CLIs and need something maintainers won't hate, this gives you the playbook.
- skills.sh installs
- 341
- GitHub stars
- 79
- last updated
- Aug 21, 2026
Install
$ npx -y skills add bobmatnyc/claude-mpm-skills --skill clap --agent claude-codeInstalls into .claude/skills of the current project.
Files
Clap (Rust) - Production CLI Patterns
Overview
Clap provides declarative command-line parsing with strong help output, validation, and subcommand support. Use it to build CLIs with predictable UX and testable execution paths.
Quick Start
Minimal CLI
✅ Correct: derive Parser
use clap::Parser;
#[derive(Parser, Debug)]
#[command(name = "mytool", version, about = "Example CLI")]
struct Args {
/// Enable verbose output
#[arg(long)]
verbose: bool,
/// Input file path
#[arg(value_name = "FILE")]
input: String,
}
fn main() {
let args = Args::parse();
if args.verbose {
eprintln!("verbose enabled");
}
println!("input={}", args.input);
}
❌ Wrong: parse multiple times
fn main() {
let _a = Args::parse();
let _b = Args::parse(); // duplicate parsing and inconsistent behavior
}
Subcommands (real tools)
Model multi-mode CLIs with subcommands and shared global flags.
✅ Correct: global flags + subcommands
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Parser, Debug)]
struct Args {
#[arg(long, global = true)]
verbose: bool,
Sponsors
Details
- Repository
- github.com/bobmatnyc/claude-mpm-skills
- Categories
- DevOps & CI/CD, Rust, CLI & Terminal
- First seen
- Jun 3, 2026
More from bobmatnyc/claude-mpm-skills
All 158- Phoenix Ops341
- Prisma Orm341
- Graphql340
- Pre Merge339
- Vb6 Legacy338
- Vercel Functions Runtime338
- Vercel Overview338
- Vercel Security Access338
- Flexlayout React337
- Digitalocean Agentic Cloud334
- Artifacts Builder333
- Vercel Ai333
- Terraform332
- Validated Handler332
- Bad Example Skill329
- Emergency Release Workflow328
- Digitalocean Teams327
- Vector Search Workflows324
- Vercel Storage Data324
- Example Framework Skill323
- Vercel Teams Billing320
- Spring Boot319
- Rust Desktop Applications263
- Api Security Review257
