aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
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 {