From d9ac0c0b077b99a025b17cb2c9b86fefa02e81ff Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 3 Oct 2019 15:54:17 +0200 Subject: [PATCH] Add argument to only list events before a certain date Signed-off-by: Matthias Beyer --- bin/domain/imag-calendar/src/main.rs | 9 ++++++++- bin/domain/imag-calendar/src/ui.rs | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/domain/imag-calendar/src/main.rs b/bin/domain/imag-calendar/src/main.rs index 82d091cf..3d8f74d0 100644 --- a/bin/domain/imag-calendar/src/main.rs +++ b/bin/domain/imag-calendar/src/main.rs @@ -173,6 +173,7 @@ fn list(rt: &Runtime) { .map_err_trace_exit_unwrap(); let do_filter_past = !scmd.is_present("list-past"); + let do_filter_before = scmd.value_of("list-before"); let ref_config = rt.config() .ok_or_else(|| format_err!("No configuration, cannot continue!")) @@ -198,7 +199,13 @@ fn list(rt: &Runtime) { true }; - allow_all_past_events(e) + let do_filter_before = do_filter_before.map(|spec| kairos_parse(spec).map_err_trace_exit_unwrap()); + + let allow_events_before_date = |event| do_filter_before.as_ref().map(|spec| { + filters::event_is_before(event, spec) + }).unwrap_or(true); + + allow_all_past_events(e) && allow_events_before_date(e) }; let mut listed_events = 0; diff --git a/bin/domain/imag-calendar/src/ui.rs b/bin/domain/imag-calendar/src/ui.rs index 9792ea9b..4c1c1898 100644 --- a/bin/domain/imag-calendar/src/ui.rs +++ b/bin/domain/imag-calendar/src/ui.rs @@ -74,6 +74,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .required(false) .multiple(false) .help("List past events")) + + .arg(Arg::with_name("list-before") + .long("before") + .takes_value(true) + .required(false) + .multiple(false) + .help("List events which are dated before certain date")) ) }