Clap derive helper attribute question

Playing with clap derive I have this sample

use clap::Parser;

#[derive(Parser)] // requires `derive` feature
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
enum CargoCli {
    ExampleDerive(ExampleDeriveArgs),
}

#[derive(clap::Args)]
#[command(author, version, about, long_about = None)]
struct ExampleDeriveArgs {
    #[arg(long)]
    manifest_path: Option<std::path::PathBuf>,
}

fn main() {
    let CargoCli::ExampleDerive(args) = CargoCli::parse();
    println!("{:?}", args.manifest_path);
}

from https://github.com/clap-rs/clap/blob/master/examples/cargo-example-derive.rs

When I change #[arg(long)] to #[clap(long)] I can still build the binary and I do not notice any difference when calling the binary.

What is the difference between arg and clap here?

If I remember correctly, #[arg] is newer and #[clap] is deprecated; presumably so that the same name clap wasn't being used in different places with different meanings.

1 Like

Thanks @kpreid . This would make sense as I used #[clap] in a program which is some years old.