diff options
author | Daniel <kingdread@gmx.de> | 2019-05-18 01:37:50 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2019-05-18 01:37:50 +0200 |
commit | 54e29430b3a668e9e98d3fc6e1a107fd36af8af4 (patch) | |
tree | d7143e4012ceb9cc8a84fc4013b2012ee4734348 /src/main.rs | |
parent | e132410e7a526239389d3e8dedbcf5a84f0503b5 (diff) | |
download | raidgrep-54e29430b3a668e9e98d3fc6e1a107fd36af8af4.tar.gz raidgrep-54e29430b3a668e9e98d3fc6e1a107fd36af8af4.tar.bz2 raidgrep-54e29430b3a668e9e98d3fc6e1a107fd36af8af4.zip |
add support for weekday filtering
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index c1c2bcb..099262c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use std::io::{self, BufReader}; use std::path::PathBuf; use std::str::FromStr; -use chrono::{Duration, NaiveDateTime}; +use chrono::{Duration, NaiveDateTime, Weekday}; use num_traits::cast::FromPrimitive; use regex::Regex; use structopt::StructOpt; @@ -113,6 +113,15 @@ pub struct Opt { )] before: Option<NaiveDateTime>, + /// Only show logs from the given weekdays. + #[structopt( + short = "w", + long = "weekdays", + default_value = "*", + parse(try_from_str = "try_from_str_simple_error") + )] + weekdays: CommaSeparatedList<Weekday>, + /// Print more debugging information to stderr. #[structopt(long = "debug")] debug: bool, @@ -206,6 +215,11 @@ fn parse_time_arg(input: &str) -> Result<NaiveDateTime, &'static str> { Err("unknown time format") } +fn try_from_str_simple_error<T: FromStr>(input: &str) -> Result<T, String> +{ + T::from_str(input).map_err(|_| format!("'{}' is an invalid value", input)) +} + fn main() { let opt = Opt::from_args(); @@ -283,6 +297,7 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE let take_log = filters::filter_name(&log, opt) == !opt.invert && filters::filter_outcome(&info, opt) + && filters::filter_weekday(&info, opt) && filters::filter_time(&info, opt); if take_log { |