Add --no-messages flag.

This flag is similar to what's found in grep: it will suppress all error
messages, such as those shown when a particular file couldn't be read.

Closes #149
This commit is contained in:
Andrew Gallant
2016-11-06 14:36:08 -05:00
parent 58aca2efb2
commit 77ad7588ae
6 changed files with 48 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ struct Options {
invert_match: bool,
line_number: bool,
max_count: Option<u64>,
no_messages: bool,
quiet: bool,
text: bool,
}
@@ -51,6 +52,7 @@ impl Default for Options {
invert_match: false,
line_number: false,
max_count: None,
no_messages: false,
quiet: false,
text: false,
}
@@ -186,7 +188,9 @@ impl Worker {
let file = match File::open(path) {
Ok(file) => file,
Err(err) => {
eprintln!("{}: {}", path.display(), err);
if !self.opts.no_messages {
eprintln!("{}: {}", path.display(), err);
}
return 0;
}
};
@@ -205,7 +209,9 @@ impl Worker {
count
}
Err(err) => {
eprintln!("{}", err);
if !self.opts.no_messages {
eprintln!("{}", err);
}
0
}
}