enables find to search records with regex (#5100)

* enables find to search records with regex

* clippy
This commit is contained in:
Darren Schroeder 2022-04-05 12:26:11 -05:00 committed by GitHub
parent d64cf1687e
commit 6e7e2dbb97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -187,9 +187,23 @@ fn find_with_regex(
.map_err(|e| ShellError::UnsupportedInput(format!("incorrect regex: {}", e), span))?;
input.filter(
move |value| {
let string = value.into_string(" ", &config);
re.is_match(string.as_str()) != invert
move |value| match value {
Value::String { val, .. } => re.is_match(val.as_str()) != invert,
Value::Record { cols: _, vals, .. } => {
let matches: Vec<bool> = vals
.iter()
.map(|v| re.is_match(v.into_string(" ", &config).as_str()) != invert)
.collect();
matches.iter().any(|b| *b)
}
Value::List { vals, .. } => {
let matches: Vec<bool> = vals
.iter()
.map(|v| re.is_match(v.into_string(" ", &config).as_str()) != invert)
.collect();
matches.iter().any(|b| *b)
}
_ => false,
},
ctrlc,
)