diff options
| author | Daniel <kingdread@gmx.de> | 2019-05-18 01:36:35 +0200 | 
|---|---|---|
| committer | Daniel <kingdread@gmx.de> | 2019-05-18 01:36:35 +0200 | 
| commit | e132410e7a526239389d3e8dedbcf5a84f0503b5 (patch) | |
| tree | 7eead807bbe2dddf0bd81ca74edc67bba19470e2 /src | |
| parent | cc4c270f5101848b8ad922b1efda678fdf377dab (diff) | |
| download | raidgrep-e132410e7a526239389d3e8dedbcf5a84f0503b5.tar.gz raidgrep-e132410e7a526239389d3e8dedbcf5a84f0503b5.tar.bz2 raidgrep-e132410e7a526239389d3e8dedbcf5a84f0503b5.zip | |
add support for -l to only output the file name
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/output.rs | 12 | 
2 files changed, 16 insertions, 2 deletions
| diff --git a/src/main.rs b/src/main.rs index 7d3c93d..c1c2bcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,6 +89,10 @@ pub struct Opt {      #[structopt(short = "v", long = "invert-match")]      invert: bool, +    /// Only show the name of matching files. +    #[structopt(short = "l", long = "files-with-matches")] +    file_name_only: bool, +      /// Disable colored output.      #[structopt(long = "no-color")]      no_color: bool, @@ -241,7 +245,7 @@ fn grep(opt: &Opt) -> Result<(), RuntimeError> {              s.spawn(move |_| {                  if is_log_file(&entry) {                      if let Some(result) = search_log(&entry, opt).unwrap() { -                        output::colored(io::stdout(), &result).unwrap(); +                        output::output(io::stdout(), opt, &result).unwrap();                      }                  }              }); diff --git a/src/output.rs b/src/output.rs index fcbda1b..148c088 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,8 +1,18 @@  use super::errors::RuntimeError; -use super::{FightOutcome, LogResult}; +use super::{FightOutcome, LogResult, Opt};  use std::io::Write; +/// Write the output to the given stream, according to the command line flags. +pub fn output<W: Write>(mut f: W, opt: &Opt, item: &LogResult) -> Result<(), RuntimeError> { +    if opt.file_name_only { +        writeln!(f, "{}", item.log_file.to_string_lossy())?; +    } else { +        colored(f, item)?; +    } +    Ok(()) +} +  /// Write the given log result to the given stream, using ANSI colors.  pub fn colored<W: Write>(mut f: W, item: &LogResult) -> Result<(), RuntimeError> {      use colored::Colorize; | 
