Proposal: Allow to create an argument that are required only for certain patterns. #2383
Answered
by
ldm0
puripuri2100
asked this question in
Q&A
-
I propose to add a function This function imposes looser constraints than the test code: let app = App::new("prog")
.arg(Arg::with_name("cfg")
.takes_value(true)
.required_paterns(&["foo", "bar"])
.long("cfg"))
.arg(Arg::with_name("foo")
.takes_value(true)
.long("foo"))
.arg(Arg::with_name("bar")
.long("bar"))
.arg(Arg::with_name("baz")
.long("baz"));
assert!(app.get_matches_from_safe(vec!["prog", "--foo", "foo", "--cfg", "cfg"]).is_ok());
assert!(app.get_matches_from_safe(vec!["prog", "--foo", "foo", "--bar", "--cfg", "cfg"]).is_ok());
assert!(app.get_matches_from_safe(vec!["prog", "--foo", "foo"]).is_err());
assert!(app.get_matches_from_safe(vec!["prog", "--bar"]).is_err());
assert!(app.get_matches_from_safe(vec!["prog", "--baz"]).is_ok());
assert!(app.get_matches_from_safe(vec!["prog", "--baz", "--cfg", "cfg"]).is_ok()); I plan the following uses:
let app = App::new("prog")
.arg(Arg::with_name("cfg")
.takes_value(true)
.required_paterns(&["key"]))
.arg(Arg::with_name("key")
.takes_value(true)
.long("key"))
.arg(Arg::with_name("list")
.long("list"));
|
Beta Was this translation helpful? Give feedback.
Answered by
ldm0
Mar 11, 2021
Replies: 2 comments 3 replies
-
I still have no idea what exactly you are asking for. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Please check this: https://docs.rs/clap/3.0.0-beta.2/clap/struct.Arg.html#method.requires_if |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pksunkara
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please check this: https://docs.rs/clap/3.0.0-beta.2/clap/struct.Arg.html#method.requires_if
and this: https://docs.rs/clap/3.0.0-beta.2/clap/struct.Arg.html#method.required_unless_present