Is it possible to gather the arguments after a double hyphen with Clap:
$ myapp some_positional_argument -z --cool -- "--extra1 one" --extra2
I'm looking to get two extra arguments: --extra1 one
and --extra2
.
Is it possible to gather the arguments after a double hyphen with Clap:
$ myapp some_positional_argument -z --cool -- "--extra1 one" --extra2
I'm looking to get two extra arguments: --extra1 one
and --extra2
.
--
usually means end of options, so Clap won't parse past that.
You could run clap twice - once to get remaining args after --
, and then second time to parse just them via https://docs.rs/clap/2.33.1/clap/struct.App.html?search=#method.get_matches_from
Okay, that's an interesting solution. Thank you for the suggestion!
I've been combing through the docs and I also just found the clap::Arg::last
and clap::Arg::allow_hyphen_values
functions which I might be able to combine to get the behavior I'm looking for...not sure yet.
Okay, I got the behavior I wanted from adding a new argument like this:
clap::App::with_name("notthatcool")
//...all the normal arguments...
.arg(
clap::Arg::with_name("extras")
.last(true)
.allow_hyphen_values(true)
.multiple(true)
)
.get_matches();
(and just for completeness) I can then get the values as String
s like this:
let extras: Vec<String> = match arg_matches.values_of("extras") {
Some(iter) => iter.map(|it| it.into()).collect(),
None => vec![]
};
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.