vanman2024/cli-builder
Overview
This skill provides modern, type-safe Rust CLI patterns using Clap 4.x. It packages ready-to-use templates, validation helpers, subcommand patterns, and environment-variable integration to accelerate building robust command-line applications. Use it to apply best practices for parsing, validation, and structured CLI design in Rust.
How this skill works
The skill supplies example templates and snippets that leverage Clap derive macros, the Parser trait, Subcommand enums, ValueEnum, and custom value parsers. It shows how to wire environment variables, provide defaults, implement validation functions for arguments, and generate shell completions and test cases. Templates are meant to be copied into your Rust project and adapted to your commands and types.
When to use it
- Creating a new Rust CLI and wanting type-safe argument parsing
- Organizing a complex tool with nested subcommands
- Adding validation for ports, paths, or constrained numeric ranges
- Supporting environment variables for secrets or configuration
- Providing user-friendly completions and automated CLI tests
Best practices
- Prefer derive macros (Parser, Subcommand) to reduce boilerplate
- Use ValueEnum for fixed choice options to get compile-time safety
- Validate inputs early with value_parser functions and clear error messages
- Expose sensible defaults with default_value_t and document via doc comments
- Treat PathBuf for file/directory args and keep flags global when needed
Example use cases
- A single-command binary that parses files, count, and verbose flags using Parser derive
- A git-like tool with multiple subcommands and global verbose/log flags
- A server CLI that validates port numbers with a custom value parser
- A deployment tool that reads API keys and DB URLs from environment vars with fallbacks
- A config tool that enforces output format choices via ValueEnum
FAQ
Enable derive and env features, for example: clap = { version = "4.5", features = ["derive", "env"] }.
How do I validate numeric ranges like port numbers?
Write a value_parser function that parses the string, checks the range, and returns Result<T, String> for Clap to use.
8 skills
This skill helps you build type-safe Rust CLIs with Clap derive macros, subcommands, validation, and env integration for robust command-line apps.
This skill enables building type-safe Typer CLIs with type hints, enums, and sub-apps for maintainable, scalable command-line tools.
This skill helps you design robust Python CLIs with Click, including groups, nested commands, validation, and templates for production-ready tooling.
This skill standardizes CLI testing patterns for Node.js and Python, enabling reliable exit code checks and output validation.
This skill helps you design interactive CLI prompts with text, list, checkbox, password, autocomplete, and conditional questions across Python and Node.js.
This skill provides battle-tested Commander.js patterns and templates to build robust Node.js CLIs with TypeScript support.
This skill helps you design robust Go CLIs with urfave/cli patterns, enabling fast, maintainable commands, flags, and hooks.
This skill helps you build robust Node.js CLIs with yargs patterns, enabling subcommands, options, middleware, validation, and reliable argument handling.