From 54e29430b3a668e9e98d3fc6e1a107fd36af8af4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 18 May 2019 01:37:50 +0200 Subject: add support for weekday filtering --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main.rs') 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, + /// 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, + /// Print more debugging information to stderr. #[structopt(long = "debug")] debug: bool, @@ -206,6 +215,11 @@ fn parse_time_arg(input: &str) -> Result { Err("unknown time format") } +fn try_from_str_simple_error(input: &str) -> Result +{ + 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, 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 { -- cgit v1.2.3