added docs and migrated name to rgs, migrated repo, added squash-lines feature
Some checks failed
ci / test (beta, ubuntu-latest, beta) (pull_request) Has been cancelled
ci / test (macos, macos-latest, nightly) (pull_request) Has been cancelled
ci / test (nightly, ubuntu-latest, nightly) (pull_request) Has been cancelled
ci / test (pinned, ubuntu-latest, 1.85.0) (pull_request) Has been cancelled
ci / test (stable, ubuntu-latest, stable) (pull_request) Has been cancelled
ci / test (stable-aarch64, ubuntu-latest, stable, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-arm-gnueabihf, ubuntu-latest, stable, armv7-unknown-linux-gnueabihf) (pull_request) Has been cancelled
ci / test (stable-arm-musleabi, ubuntu-latest, stable, armv7-unknown-linux-musleabi) (pull_request) Has been cancelled
ci / test (stable-arm-musleabihf, ubuntu-latest, stable, armv7-unknown-linux-musleabihf) (pull_request) Has been cancelled
ci / test (stable-musl, ubuntu-latest, stable, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
ci / test (stable-powerpc64, ubuntu-latest, stable, powerpc64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-riscv64, ubuntu-latest, stable, riscv64gc-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-s390x, ubuntu-latest, stable, s390x-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-x86, ubuntu-latest, stable, i686-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (win-gnu, windows-latest, nightly-x86_64-gnu) (pull_request) Has been cancelled
ci / test (win-msvc, windows-latest, nightly) (pull_request) Has been cancelled
ci / test (winaarch64-msvc, windows-11-arm, nightly) (pull_request) Has been cancelled
ci / wasm (pull_request) Has been cancelled
ci / rustfmt (pull_request) Has been cancelled
ci / docs (pull_request) Has been cancelled
ci / Compile Fuzz Test Targets (pull_request) Has been cancelled
Some checks failed
ci / test (beta, ubuntu-latest, beta) (pull_request) Has been cancelled
ci / test (macos, macos-latest, nightly) (pull_request) Has been cancelled
ci / test (nightly, ubuntu-latest, nightly) (pull_request) Has been cancelled
ci / test (pinned, ubuntu-latest, 1.85.0) (pull_request) Has been cancelled
ci / test (stable, ubuntu-latest, stable) (pull_request) Has been cancelled
ci / test (stable-aarch64, ubuntu-latest, stable, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-arm-gnueabihf, ubuntu-latest, stable, armv7-unknown-linux-gnueabihf) (pull_request) Has been cancelled
ci / test (stable-arm-musleabi, ubuntu-latest, stable, armv7-unknown-linux-musleabi) (pull_request) Has been cancelled
ci / test (stable-arm-musleabihf, ubuntu-latest, stable, armv7-unknown-linux-musleabihf) (pull_request) Has been cancelled
ci / test (stable-musl, ubuntu-latest, stable, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
ci / test (stable-powerpc64, ubuntu-latest, stable, powerpc64-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-riscv64, ubuntu-latest, stable, riscv64gc-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-s390x, ubuntu-latest, stable, s390x-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (stable-x86, ubuntu-latest, stable, i686-unknown-linux-gnu) (pull_request) Has been cancelled
ci / test (win-gnu, windows-latest, nightly-x86_64-gnu) (pull_request) Has been cancelled
ci / test (win-msvc, windows-latest, nightly) (pull_request) Has been cancelled
ci / test (winaarch64-msvc, windows-11-arm, nightly) (pull_request) Has been cancelled
ci / wasm (pull_request) Has been cancelled
ci / rustfmt (pull_request) Has been cancelled
ci / docs (pull_request) Has been cancelled
ci / Compile Fuzz Test Targets (pull_request) Has been cancelled
This commit is contained in:
@@ -134,6 +134,8 @@ pub(super) const FLAGS: &[&dyn Flag] = &[
|
||||
&Text,
|
||||
&Threads,
|
||||
&Trace,
|
||||
&Squash,
|
||||
&SquashNlOnly,
|
||||
&Trim,
|
||||
&Type,
|
||||
&TypeNot,
|
||||
@@ -4187,7 +4189,14 @@ This overrides the \flag{stop-on-nonmatch} flag.
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
args.multiline = v.unwrap_switch();
|
||||
let enabled = v.unwrap_switch();
|
||||
if !enabled && args.multiline_window.is_some() {
|
||||
anyhow::bail!(
|
||||
"--no-multiline cannot be used with --multiline-window \
|
||||
(which implicitly enables --multiline)"
|
||||
);
|
||||
}
|
||||
args.multiline = enabled;
|
||||
if args.multiline {
|
||||
args.stop_on_nonmatch = false;
|
||||
}
|
||||
@@ -4219,6 +4228,9 @@ impl Flag for MultilineWindow {
|
||||
fn is_switch(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn name_short(&self) -> Option<u8> {
|
||||
Some(b'W')
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"multiline-window"
|
||||
}
|
||||
@@ -4236,7 +4248,7 @@ impl Flag for MultilineWindow {
|
||||
Limit the maximum number of lines that a multiline match may span to
|
||||
\fINUM\fP (use \fB--multiline-window=\fP\fINUM\fP).
|
||||
.sp
|
||||
This flag requires \flag{multiline}. Matches are found as if the file being
|
||||
This flag implicitly enables \flag{multiline}. Matches are found as if the file being
|
||||
searched were limited to \fINUM\fP lines at a time, which can prevent
|
||||
unintended long matches while still enabling multi-line searching.
|
||||
.sp
|
||||
@@ -4250,6 +4262,7 @@ The value of \fINUM\fP must be at least 1.
|
||||
anyhow::bail!("--multiline-window must be at least 1");
|
||||
}
|
||||
args.multiline_window = Some(lines);
|
||||
args.multiline = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -4262,6 +4275,11 @@ fn test_multiline_window() {
|
||||
|
||||
let args = parse_low_raw(["--multiline-window=2"]).unwrap();
|
||||
assert_eq!(Some(2), args.multiline_window);
|
||||
assert_eq!(true, args.multiline);
|
||||
|
||||
let args = parse_low_raw(["-W", "3"]).unwrap();
|
||||
assert_eq!(Some(3), args.multiline_window);
|
||||
assert_eq!(true, args.multiline);
|
||||
}
|
||||
|
||||
/// --multiline-dotall
|
||||
@@ -6866,6 +6884,88 @@ fn test_trace() {
|
||||
assert_eq!(Some(LoggingMode::Trace), args.logging);
|
||||
}
|
||||
|
||||
/// --squash
|
||||
#[derive(Debug)]
|
||||
struct Squash;
|
||||
|
||||
impl Flag for Squash {
|
||||
fn is_switch(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"squash"
|
||||
}
|
||||
fn doc_category(&self) -> Category {
|
||||
Category::Output
|
||||
}
|
||||
fn doc_short(&self) -> &'static str {
|
||||
r"Squash contiguous whitespace in output to a single space."
|
||||
}
|
||||
fn doc_long(&self) -> &'static str {
|
||||
r#"
|
||||
Squash any contiguous Unicode whitespace (including new lines) into a single
|
||||
ASCII space when printing matches.
|
||||
"#
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
assert!(v.unwrap_switch(), "--squash can only be enabled");
|
||||
args.squash = grep::printer::SquashMode::Whitespace;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_squash() {
|
||||
let args = parse_low_raw(None::<&str>).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::None, args.squash);
|
||||
|
||||
let args = parse_low_raw(["--squash"]).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::Whitespace, args.squash);
|
||||
}
|
||||
|
||||
/// --squash-nl-only
|
||||
#[derive(Debug)]
|
||||
struct SquashNlOnly;
|
||||
|
||||
impl Flag for SquashNlOnly {
|
||||
fn is_switch(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn name_long(&self) -> &'static str {
|
||||
"squash-nl-only"
|
||||
}
|
||||
fn doc_category(&self) -> Category {
|
||||
Category::Output
|
||||
}
|
||||
fn doc_short(&self) -> &'static str {
|
||||
r"Squash new lines into spaces in output."
|
||||
}
|
||||
fn doc_long(&self) -> &'static str {
|
||||
r#"
|
||||
Squash contiguous line terminators into a single ASCII space when printing
|
||||
matches. Other whitespace is preserved.
|
||||
"#
|
||||
}
|
||||
|
||||
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
|
||||
assert!(v.unwrap_switch(), "--squash-nl-only can only be enabled");
|
||||
args.squash = grep::printer::SquashMode::Newlines;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_squash_nl_only() {
|
||||
let args = parse_low_raw(None::<&str>).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::None, args.squash);
|
||||
|
||||
let args = parse_low_raw(["--squash-nl-only"]).unwrap();
|
||||
assert_eq!(grep::printer::SquashMode::Newlines, args.squash);
|
||||
}
|
||||
|
||||
/// --trim
|
||||
#[derive(Debug)]
|
||||
struct Trim;
|
||||
|
||||
Reference in New Issue
Block a user