How to let clap v4 allow multiple occurrences?
⚓ Rust 📅 2026-01-19 👤 surdeus 👁️ 8I want my program to allow multiple occurrences of a flag. The flag isn't a vector, so action = ArgAction::Append doesn't work for me, and I want the last occurrence to take priority. I haven't found any way to do this yet.
struct Args {
/// Input files
files: Vec<String>
#[arg(short, long, default_value = "mystruct")]
flag: MyStruct
}
With my current code, running my_program --flag value1 --flag value2 raises an error:
error: the argument '--flag <FLAG>' cannot be used multiple times
Usage: my_program [OPTIONS] [FILES]...
For more information, try '--help'.
4 posts - 2 participants
🏷️ Rust_feed