-
I'm trying to emulate the argument structure of an existing command, which parses options at the start of the arguments, then a positional argument, followed by arbitrary other options, which are unparsed (specifically, they may look like options, but they are not to be treated as such). Something like
I want to get Is this possible with clap? I don't want to debate whether this is a "good" CLI structure - I know it doesn't follow the normal (POSIX?) conventions, but matching the usage of some existing commands is the most important thing here, and I'm just hoping I don't have to implement my own argument parser just for this... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
This is not possible with clap. |
Beta Was this translation helpful? Give feedback.
-
And the final version, which is impressively straightforward: struct Args {
#[arg(short, long)]
include: Vec<String>,
script: String,
#[arg(trailing_var_arg=true, allow_hyphen_values=true)]
script_args: Vec<String>,
}
Sorry I didn't manage to find this myself in the first place - my search skills were obviously lacking. The key result that set me on the right path was here. |
Beta Was this translation helpful? Give feedback.
And the final version, which is impressively straightforward:
trailing_var_arg
lets the last positional argument pick everything up, andallow_hyphen_values
ensures that it accepts arguments with leading hyphens, rather than trying to parse them as options.Sorry I didn't manage to find this myself in the first place - my search skills were obviously lacking. The key result that set me on the right path was here.