Details

Language / Topic
rustRust
Category
Libraries
Source
clap-rs

Rules

balanced
- Use derive macros: `#[derive(Parser)]` on a struct with `#[arg()]` attributes on fields — Clap generates the CLI parser at compile time.
- Use `#[command(about, version)]` for auto-generated help text and `#[arg(short, long, default_value)]` for flag configuration.
- Use subcommands with `#[derive(Subcommand)]` enum and `#[command(subcommand)]` field on the main struct — pattern match in `main()`.
- Use `#[arg(default_value_t = ...)]` for defaults, `#[arg(value_enum)]` for enum arguments.
- Use `#[command(about, version, author)]` for auto-generated help text.
- Group related arguments into subcommand structs with `#[derive(Subcommand)]`.
- Use `#[arg(env = "MY_VAR")]` to allow arguments from environment variables.