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-code

Installs 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
1jezweb avatarcloudflare-workflowsjezweb/claude-skillsBuild durable workflows with Cloudflare Workflows (GA April 2025). Features step.do, step.sleep, waitForEvent, Vitest testing, automatic retries, and state pers341skills.sh installs
2pmprompt avatarhierarchy-of-marketplacespmprompt/claude-plugin-product-managementUse when asked about "marketplace strategy", "chicken and egg problem", "liquidity", "two-sided market", "tipping a marketplace", "GMV growth", or "Sarah Tavel 341skills.sh installs
3jamesrochabrun avatarfrontend-designerjamesrochabrun/skillsBuild accessible, responsive, and performant frontend components with design system best practices, modern CSS, and framework-agnostic patterns.340skills.sh installs
4jeremylongshore avatartracking-crypto-pricesjeremylongshore/claude-code-plugins-plus-skillsTrack real-time cryptocurrency prices across exchanges with historical data and alerts. Provides price data infrastructure for dependent skills (portfolio, tax,340skills.sh installs
5krutikjain avatarandroid-compose-foundationskrutikjain/android-agent-skillsBuild Android UI with Jetpack Compose foundations, layouts, modifiers, theming, and stable component structure.340skills.sh installs
6sharpdeveye avatarextract-patternsharpdeveye/maestroUse when the user wants to create templates, extract reusable patterns, document solutions, or build a pattern library from working workflows.340skills.sh installs