mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
Add option to invert match command selection (#3114)
* Add option to invert match command selection * Fix rustfmt error * Rename match --exclude to --invert To be more descriptive and conform to e.g. grep or ripgrep -v flag. Also simplified the --invert flag description. * Fix formatting when description got shorter Co-authored-by: Jakub Žádník <jakub.zadnik@tuni.fi>
This commit is contained in:
parent
f83ff0e47d
commit
28a6a5ea57
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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![])
|
||||
|
Loading…
Reference in New Issue
Block a user