Search code examples
rustcommand-line-interfaceclap

Is it possible to have multiple long names for the same command-line argument?


Let's show what I mean with an example of a program argument:

-q, --quiet, --silent: Don't show output

I tried to do

#[derive(Parser)]
#[command(version = "0.1.0")]
struct Args {
  // ...
  #[arg(short, long = ["quiet", "silent"], default_value_t = false)]
  quiet: bool,
}

but rust gives me an error because the long argument takes a string, not an array, but is there a workaround using clap to have multiple possible names for the same argument ?


Solution

  • I need to use the alias argument to arg for that (or visible_alias if I want it to display on the help message)

    #[arg(short, long, visible_alias = "silent")]
    quiet: bool,