How to Use Derive-Based Argument Parsing with clap

Use the #[derive(Parser)] attribute on a struct to automatically handle command-line argument parsing with clap.

Use the #[derive(Parser)] attribute on a struct to automatically generate command-line argument parsing logic for clap.

use clap::Parser;

#[derive(Parser, Debug)]
#[command(name = "minigrep")]
struct Config {
    #[arg(short, long)]
    query: String,

    #[arg(short, long)]
    file_path: String,
}

fn main() {
    let config = Config::parse();
    println!("Searching for {} in {}", config.query, config.file_path);
}

This replaces manual env::args() parsing and Config::build() methods with a single Config::parse() call.