You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
One of the use cases the documentation lists for ArgGroup is to have a set of mutually exclusive arguments (with .multiple(false)), but the only way to get which of those arguments was passed is to call matches.is_present(name) for every argument in that group. It would be really nice if I could just get which argument of a mutually exclusive argument group was passed. Currently, to do this you have to check each argument individually, doing something like:
let directions = &["left","right","forward"];let matches = App::new("ArgGroup test").arg(Arg::with_name("left").short("-l").long("--left")).arg(Arg::with_name("right").short("-r").long("--right")).arg(Arg::with_name("forward").short("-f").long("--forward")).group(ArgGroup::with_name("direction").required(true).multiple(false).args(directions)).get_matches();letmut passed_direction = None;for direction in directions {if matches.is_present(direction){
passed_direction = Some(direction);}}let passed_direction = passed_direction.unwrap();
Which is kind of tedious, and not very clean.
Describe the solution you'd like
Being able to write something like:
let matches = App::new("ArgGroup test").arg(Arg::with_name("left").short("-l").long("--left")).arg(Arg::with_name("right").short("-r").long("--right")).arg(Arg::with_name("forward").short("-f").long("--forward")).group(ArgGroup::with_name("direction").required(true).multiple(false).args(&["left","right","forward"])).get_matches();let passed_direction = matches.value_of("direction");
would be really nice. value_of() is just an example, there — I'm not particular about the exact API is to get this 🙂
The text was updated successfully, but these errors were encountered:
Comment by Qyriad Friday Jan 29, 2021 at 18:39 GMT
she*, but I believe you're correct. ArgGroup::multiple() already sets the mutual exclusivity. I'm looking for a way to get which argument in an ArgGroup was passed, from an ArgMatches. I don't see how conflicts_with_all() helps me there.
Comment by Qyriad Saturday Jan 30, 2021 at 15:54 GMT
So we need to design a new api specifically for fetching the triggered argument and also the value?
Ideally, though I would also be fine with an API just for fetching the triggered argument — which would mean that getting the value of that argument would be a separate step.
Issue by Qyriad
Thursday Jan 28, 2021 at 20:44 GMT
Originally opened as clap-rs/clap#2317
Make sure you completed the following tasks
Describe your use case
One of the use cases the documentation lists for
ArgGroup
is to have a set of mutually exclusive arguments (with.multiple(false)
), but the only way to get which of those arguments was passed is to callmatches.is_present(name)
for every argument in that group. It would be really nice if I could just get which argument of a mutually exclusive argument group was passed. Currently, to do this you have to check each argument individually, doing something like:Which is kind of tedious, and not very clean.
Describe the solution you'd like
Being able to write something like:
would be really nice.
value_of()
is just an example, there — I'm not particular about the exact API is to get this 🙂The text was updated successfully, but these errors were encountered: