Clap: how to disable options after a certain positional argument
⚓ Rust 📅 2026-05-16 👤 surdeus 👁️ 4I'm thinking of something like trailing_var_arg:
#[derive(Parser)]
struct Bash {
#[clap(short)]
pub e: bool
pub file: String,
#[calp(allow_hyphen_values = true, trailing_var_args = true]
pub more_args: Vec<String>
}
I want everything after file to be supplied to more_args, even if it looks liks an option .
The above code works in some cases. If user type "bash a.sh x -e", more_args becomes ["x", "-e"].
However, if "-e" is the first value, like "bash a.sh -e x", it will be provided to the option instead of positional args. Which makes sense because the positional argument doesn't even begin. User have to type "bash a.sh -- -e x" instead.
But I can't see anywhere in the document how to achieve what I want.
Is there a way to let clap know, after a certain positioal argument, every option should be disabled?
1 post - 1 participant
🏷️ Rust_feed