diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-04-06 18:02:45 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-04-13 12:23:46 +0200 |
commit | e8da6232d1bee97e72af95f5f67c6df756667038 (patch) | |
tree | 472be4db9b443bd7eeb4b83af755e515b2ec4431 | |
parent | f2b0e6581497957c95e8b8188d962d1445695653 (diff) |
Fix: Do not write data if output is pipe
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | bin/core/imag-grep/src/lib.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/bin/core/imag-grep/src/lib.rs b/bin/core/imag-grep/src/lib.rs index 76ea5bca..53101a3f 100644 --- a/bin/core/imag-grep/src/lib.rs +++ b/bin/core/imag-grep/src/lib.rs @@ -120,12 +120,16 @@ impl ImagApplication for ImagGrep { .len(); if opts.count { - writeln!(rt.stdout(), "{}", count)?; + if !rt.output_is_pipe() || rt.output_data_pipe() { + writeln!(rt.stdout(), "{}", count)?; + } } else if !opts.files_with_matches { - writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches", - overall_count, - count, - overall_count - count)?; + if !rt.output_is_pipe() || rt.output_data_pipe() { + writeln!(rt.stdout(), "Processed {} files, {} matches, {} nonmatches", + overall_count, + count, + overall_count - count)?; + } } Ok(()) @@ -150,6 +154,11 @@ impl ImagApplication for ImagGrep { } fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize) -> Result<()> { + if rt.output_is_pipe() && !rt.output_data_pipe() { + // leave if output is a pipe and behaviour is not overridden + return Ok(()) + } + if opts.files_with_matches { writeln!(rt.stdout(), "{}", e.get_location())?; } else if opts.count { |