Replies: 3 comments 2 replies
-
|
We're running into the same issue over here: spinel-coop/rv#426. It seems like it should be possible to tell clap we want Why can't we set |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, this was posted during a very busy time for me and I apparently haven't made it this far back into my backlog. There are multiple use cases and we need to separate them out
So that would be: #[derive(Parser, Debug)]
pub struct ExecCommandOneArg {
#[arg(long, short = 'x')]
some_option: Option<String>,
/// Command with arguments
#[arg(required = true, trailing_var_arg = true)]
args: Vec<String>,
} |
Beta Was this translation helpful? Give feedback.
-
|
As for the confusion over |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This does pop up from time to time and the answer seems to be generally "trailing_var_arg + allow_hyphen_values", but this has various unexpected failure modes. Summary of the tests below:
Regular positional arg (e.g. binary name) followed by var_arg (e.g. options for the binary) fails like this:
-xfoo), sometimes picked up (-xfoo). Seems like a bug to me.Single var_arg for everything fails like this
-xfoois parsed as an option, while-xfoostarts the var_arg. Seems like a bug to me.Single var_arg with
last = trueappears to be the only option that reliably works, but has the following drawbacks:--, even though the resulting parser isn't generally ambigiuous under getopt/getopt_long rules (any positional terminates parsing of options and flags).This use case seems common enough that there should be one preferred and documented way to do it which does not fail in strange ways. Most of the odd behavior here seems to come from clap's decision to allow mixing positional arguments with options and flags (much like argparse does, though clap seems to have fewer bugs than argparse). I've looked around and haven't seen anything to disable this (ime undesirable) behavior.
Beta Was this translation helpful? Give feedback.
All reactions