Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 810
Fayeure Avatar asked Dec 06 '25 16:12

Fayeure


1 Answers

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,
like image 132
Fayeure Avatar answered Dec 09 '25 18:12

Fayeure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!