Add argument to only list events after a certain date
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
d9ac0c0b07
commit
d201797b98
3 changed files with 20 additions and 1 deletions
|
@ -61,6 +61,10 @@ pub fn event_is_before<'a>(event: &Event<'a>, before_spec: &NaiveDateTime) -> bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn event_is_after<'a>(event: &Event<'a>, after_spec: &NaiveDateTime) -> bool {
|
||||||
|
!event_is_before(event, after_spec)
|
||||||
|
}
|
||||||
|
|
||||||
fn try_to_parse_datetime(s: &str) -> Result<NaiveDateTime> {
|
fn try_to_parse_datetime(s: &str) -> Result<NaiveDateTime> {
|
||||||
const FORMATS : &[&'static str] = &[
|
const FORMATS : &[&'static str] = &[
|
||||||
"%Y%m%dT%H%M%S",
|
"%Y%m%dT%H%M%S",
|
||||||
|
|
|
@ -174,6 +174,7 @@ fn list(rt: &Runtime) {
|
||||||
|
|
||||||
let do_filter_past = !scmd.is_present("list-past");
|
let do_filter_past = !scmd.is_present("list-past");
|
||||||
let do_filter_before = scmd.value_of("list-before");
|
let do_filter_before = scmd.value_of("list-before");
|
||||||
|
let do_filter_after = scmd.value_of("list-after");
|
||||||
|
|
||||||
let ref_config = rt.config()
|
let ref_config = rt.config()
|
||||||
.ok_or_else(|| format_err!("No configuration, cannot continue!"))
|
.ok_or_else(|| format_err!("No configuration, cannot continue!"))
|
||||||
|
@ -205,7 +206,14 @@ fn list(rt: &Runtime) {
|
||||||
filters::event_is_before(event, spec)
|
filters::event_is_before(event, spec)
|
||||||
}).unwrap_or(true);
|
}).unwrap_or(true);
|
||||||
|
|
||||||
allow_all_past_events(e) && allow_events_before_date(e)
|
|
||||||
|
let do_filter_after = do_filter_after.map(|spec| kairos_parse(spec).map_err_trace_exit_unwrap());
|
||||||
|
|
||||||
|
let allow_events_after_date = |event| do_filter_after.as_ref().map(|spec| {
|
||||||
|
filters::event_is_after(event, spec)
|
||||||
|
}).unwrap_or(true);
|
||||||
|
|
||||||
|
allow_all_past_events(e) && allow_events_before_date(e) && allow_events_after_date(e)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut listed_events = 0;
|
let mut listed_events = 0;
|
||||||
|
|
|
@ -81,6 +81,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.required(false)
|
.required(false)
|
||||||
.multiple(false)
|
.multiple(false)
|
||||||
.help("List events which are dated before certain date"))
|
.help("List events which are dated before certain date"))
|
||||||
|
|
||||||
|
.arg(Arg::with_name("list-after")
|
||||||
|
.long("after")
|
||||||
|
.takes_value(true)
|
||||||
|
.required(false)
|
||||||
|
.multiple(false)
|
||||||
|
.help("List events which are dated after certain date"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue