From 6e7e2dbb97247633161ebcb12c9fc1cb1fbcc7a8 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 5 Apr 2022 12:26:11 -0500 Subject: [PATCH] enables find to search records with regex (#5100) * enables find to search records with regex * clippy --- crates/nu-command/src/filters/find.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index f1c473d437..f998354621 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -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 = 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 = vals + .iter() + .map(|v| re.is_match(v.into_string(" ", &config).as_str()) != invert) + .collect(); + matches.iter().any(|b| *b) + } + _ => false, }, ctrlc, )