Fix core dump with mutually requires() args

Fixes #1643
This commit is contained in:
CreepySkeleton 2020-03-03 22:00:35 +03:00
parent c192f5effb
commit 839ed2588c
2 changed files with 34 additions and 0 deletions

View file

@ -1922,10 +1922,17 @@ impl<'b> App<'b> {
}
};
let mut processed = vec![];
let mut r_vec = vec![arg];
let mut args = vec![];
while let Some(a) = r_vec.pop() {
if processed.contains(&a) {
continue;
}
processed.push(a);
if let Some(arg) = self.find(a) {
if let Some(ref reqs) = arg.requires {
for r in reqs.iter().filter_map(requires_if_or_not) {

View file

@ -703,3 +703,30 @@ fn issue_1158_conflicting_requirements_rev() {
assert!(res.is_ok());
}
#[test]
fn issue_1643_args_mutually_require_each_other() {
use clap::*;
fn main() {
let app = App::new("test")
.arg(
Arg::with_name("relation_id")
.help("The relation id to get the data from")
.long("relation-id")
.short('r')
.takes_value(true)
.requires("remote_unit_name"),
)
.arg(
Arg::with_name("remote_unit_name")
.help("The name of the remote unit to get data from")
.long("remote-unit")
.short('u')
.takes_value(true)
.requires("relation_id"),
);
app.get_matches_from(&["test", "-u", "hello"]);
}
}