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 {

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

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


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.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.