jwh20
1
I'm using Clap to parse my command line and need to support the following:
mycommand [--somearg1 value --alsorequired another value] | [--somearg2 value --requiredfor2 value]
Basically if --somearg1 is specified, then --alsorequired is required. But if --somearg2 is specified, --requiredfor2 is required.
I'd have thought that ArgGroups would cover this use case but it doesn't seem to address it.
jwh20
3
Thanks! That helped a lot. Here is what I ended up with:
let matches = Command::new("prog")
.arg(arg!(--two <VALUE>).required(false).requires("three"))
.arg(arg!(--three <VALUE>))
.arg(arg!(--four <VALUE>).exclusive(true))
.get_matches();
So in this case --two requires --three and --four is exclusive.
system
Closed
4
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.