Repeat the same argument several times



examples/clap/repeat-the-same-argument/src/main.rs
use clap::Parser;

#[derive(Parser, Debug)]
struct Cli {
    #[arg(long)]
    animal: Vec<String>,
}

fn main() {
    let args = Cli::parse();
    println!("{args:?}");
}

$ cargo run -q
Cli { animal: [] }

$ cargo run -q -- --animal Cat
Cli { animal: ["Cat"] }

$ cargo run -q -- --animal Cat Dog
error: unexpected argument 'Dog' found

Usage: repeat-the-same-argument [OPTIONS]

For more information, try '--help'.

$ cargo run -q -- --animal Cat --animal Dog
Cli { animal: ["Cat", "Dog"] }