clap-scaffolder

Generate Clap-based Rust CLI applications with derive macros, subcommands, and modern Rust patterns. Creates production-ready Rust CLI with proper cargo structure.

509 stars

Best use case

clap-scaffolder is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generate Clap-based Rust CLI applications with derive macros, subcommands, and modern Rust patterns. Creates production-ready Rust CLI with proper cargo structure.

Teams using clap-scaffolder should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/clap-scaffolder/SKILL.md --create-dirs "https://raw.githubusercontent.com/a5c-ai/babysitter/main/library/specializations/cli-mcp-development/skills/clap-scaffolder/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/clap-scaffolder/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How clap-scaffolder Compares

Feature / Agentclap-scaffolderStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generate Clap-based Rust CLI applications with derive macros, subcommands, and modern Rust patterns. Creates production-ready Rust CLI with proper cargo structure.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Clap Scaffolder

Generate a complete Clap CLI application with Rust, derive macros, and best practices.

## Capabilities

- Generate Rust-based Clap CLI projects using derive macros
- Create subcommand hierarchies with nested enums
- Set up argument parsing with type validation
- Configure shell completion generation
- Implement colored output with anyhow error handling
- Set up cargo workspace and build configurations

## Usage

Invoke this skill when you need to:
- Bootstrap a new CLI application using Clap
- Create a Rust CLI with type-safe argument parsing
- Leverage derive macros for declarative command definitions
- Build fast, native cross-platform binaries

## Inputs

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| projectName | string | Yes | Name of the CLI project (kebab-case) |
| description | string | Yes | Short description of the CLI |
| commands | array | No | List of commands to scaffold |
| deriveFeatures | array | No | Clap derive features to enable |
| colorOutput | boolean | No | Enable colored output (default: true) |

### Command Structure

```json
{
  "commands": [
    {
      "name": "run",
      "description": "Run the application",
      "args": [
        { "name": "target", "help": "Target to run", "required": true }
      ],
      "options": [
        { "long": "watch", "short": "w", "help": "Watch for changes" },
        { "long": "port", "short": "p", "value_name": "PORT", "default": "3000" }
      ]
    }
  ]
}
```

## Output Structure

```
<projectName>/
├── Cargo.toml
├── Cargo.lock
├── README.md
├── .gitignore
├── src/
│   ├── main.rs              # Entry point
│   ├── cli.rs               # Clap definitions
│   ├── commands/
│   │   ├── mod.rs           # Command exports
│   │   └── <command>.rs     # Individual commands
│   ├── config.rs            # Configuration
│   └── error.rs             # Error types
├── tests/
│   └── cli.rs               # CLI integration tests
└── completions/
    ├── _<projectName>       # Zsh completions
    ├── <projectName>.bash   # Bash completions
    └── <projectName>.fish   # Fish completions
```

## Generated Code Patterns

### CLI Definition (src/cli.rs)

```rust
use clap::{Parser, Subcommand, Args};

#[derive(Parser)]
#[command(name = "<projectName>")]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    /// Enable verbose output
    #[arg(short, long, global = true)]
    pub verbose: bool,

    /// Configuration file path
    #[arg(short, long, global = true)]
    pub config: Option<PathBuf>,

    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Run the application
    Run(RunArgs),
    /// Build the project
    Build(BuildArgs),
    /// Generate shell completions
    Completions {
        /// Shell to generate completions for
        #[arg(value_enum)]
        shell: clap_complete::Shell,
    },
}

#[derive(Args)]
pub struct RunArgs {
    /// Target to run
    pub target: String,

    /// Watch for changes
    #[arg(short, long)]
    pub watch: bool,

    /// Port to use
    #[arg(short, long, default_value = "3000")]
    pub port: u16,
}
```

### Main Entry (src/main.rs)

```rust
use anyhow::Result;
use clap::Parser;
use colored::Colorize;

mod cli;
mod commands;
mod config;
mod error;

use cli::{Cli, Commands};

fn main() -> Result<()> {
    let cli = Cli::parse();

    // Setup logging based on verbosity
    if cli.verbose {
        env_logger::Builder::from_env(
            env_logger::Env::default().default_filter_or("debug")
        ).init();
    }

    match cli.command {
        Commands::Run(args) => commands::run::execute(args)?,
        Commands::Build(args) => commands::build::execute(args)?,
        Commands::Completions { shell } => {
            generate_completions(shell);
        }
    }

    Ok(())
}
```

### Command Implementation

```rust
use anyhow::Result;
use colored::Colorize;

use crate::cli::RunArgs;

pub fn execute(args: RunArgs) -> Result<()> {
    println!("{} Running target: {}", "→".blue(), args.target.green());

    if args.watch {
        println!("{} Watch mode enabled", "!".yellow());
    }

    println!("{} Listening on port {}", "✓".green(), args.port);

    Ok(())
}
```

## Dependencies

```toml
[package]
name = "<projectName>"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.4", features = ["derive", "env"] }
clap_complete = "4.4"
anyhow = "1.0"
thiserror = "1.0"
colored = "2.0"
env_logger = "0.10"
log = "0.4"

[dev-dependencies]
assert_cmd = "2.0"
predicates = "3.0"
```

## Workflow

1. **Validate inputs** - Check project name, commands structure
2. **Create directory structure** - Set up Rust project layout
3. **Generate Cargo.toml** - Configure dependencies and metadata
4. **Create CLI definition** - Clap derive structs
5. **Generate commands** - Individual command modules
6. **Create utilities** - Config, error handling
7. **Generate completions** - Shell completion scripts
8. **Set up tests** - CLI integration tests

## Best Practices Applied

- Derive macros for declarative definitions
- Anyhow for error handling
- Colored output for user feedback
- Environment variable support
- Built-in completion generation
- Cross-platform compatible

## References

- Clap Documentation: https://docs.rs/clap/
- Clap GitHub: https://github.com/clap-rs/clap
- Rust CLI Book: https://rust-cli.github.io/book/

## Target Processes

- cli-application-bootstrap
- argument-parser-setup
- shell-completion-scripts

Related Skills

yargs-scaffolder

509
from a5c-ai/babysitter

Generate Yargs-based CLI applications with commands, positional args, middleware, and TypeScript support. Creates a complete scaffolded CLI application with modern patterns.

textual-scaffolder

509
from a5c-ai/babysitter

Generate Textual (Python) TUI application structure with widgets, screens, and CSS styling.

oclif-scaffolder

509
from a5c-ai/babysitter

Generate oclif CLI framework projects with plugin support, topics, hooks, and TypeScript. Creates enterprise-grade CLI applications with extensibility.

commander-js-scaffolder

509
from a5c-ai/babysitter

Generate Commander.js CLI project structure with TypeScript, commands, options, and best practices. Creates a complete scaffolded CLI application ready for development.

cobra-scaffolder

509
from a5c-ai/babysitter

Generate Cobra/Viper-based Go CLI applications with persistent flags, subcommands, and configuration management. Creates production-ready Go CLI with modern patterns.

click-scaffolder

509
from a5c-ai/babysitter

Generate Click-based Python CLI applications with decorators, groups, context, and modern Python patterns. Creates complete scaffolded CLI with proper project structure.

bubble-tea-scaffolder

509
from a5c-ai/babysitter

Generate Bubble Tea (Go) TUI application structure with models, commands, and views using the Elm architecture.

bats-test-scaffolder

509
from a5c-ai/babysitter

Generate BATS test structure and fixtures for shell script testing with setup/teardown, assertions, and mocking.

argparse-scaffolder

509
from a5c-ai/babysitter

Generate argparse-based Python CLI applications with subparsers, type converters, and standard library patterns. Creates lightweight Python CLIs without external dependencies.

process-builder

509
from a5c-ai/babysitter

Scaffold new babysitter process definitions following SDK patterns, proper structure, and best practices. Guides the 3-phase workflow from research to implementation.

Workflow & Productivity

babysitter

509
from a5c-ai/babysitter

Orchestrate via @babysitter. Use this skill when asked to babysit a run, orchestrate a process or whenever it is called explicitly. (babysit, babysitter, orchestrate, orchestrate a run, workflow, etc.)

yolo

509
from a5c-ai/babysitter

Run Babysitter autonomously with minimal manual interruption.