diff --git a/crates/nu_plugin_match/src/match_.rs b/crates/nu_plugin_match/src/match_.rs index 896e2188ad..b90c5e2dca 100644 --- a/crates/nu_plugin_match/src/match_.rs +++ b/crates/nu_plugin_match/src/match_.rs @@ -3,6 +3,7 @@ use regex::Regex; pub struct Match { pub column: String, pub regex: Regex, + pub invert: bool, } impl Match { @@ -11,6 +12,7 @@ impl Match { Ok(Match { column: String::new(), regex: Regex::new("")?, + invert: false, }) } } diff --git a/crates/nu_plugin_match/src/nu/mod.rs b/crates/nu_plugin_match/src/nu/mod.rs index 10b0a5b466..887044f107 100644 --- a/crates/nu_plugin_match/src/nu/mod.rs +++ b/crates/nu_plugin_match/src/nu/mod.rs @@ -24,6 +24,7 @@ impl Plugin for Match { "dotall mode: allow a dot . to match newline character \\n", Some('s'), ) + .switch("invert", "invert the match", Some('v')) .filter()) } @@ -31,6 +32,7 @@ impl Plugin for Match { let insensitive = call_info.args.has("insensitive"); let multiline = call_info.args.has("multiline"); let dotall = call_info.args.has("dotall"); + self.invert = call_info.args.has("invert"); if let Some(args) = call_info.args.positional { match &args[0] { Value { @@ -113,7 +115,7 @@ impl Plugin for Match { return Err(ShellError::labeled_error("Expected row", "value", tag)); } } - if flag { + if flag ^ self.invert { Ok(vec![Ok(ReturnSuccess::Value(input))]) } else { Ok(vec![])