From 53bf1a513b81cf85e132005219f6370f119bea84 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 21 Jan 2018 22:28:50 +0100 Subject: [PATCH] Implement stopping all tags which are started --- bin/domain/imag-timetrack/src/stop.rs | 31 +++++++++++++++++++++------ bin/domain/imag-timetrack/src/ui.rs | 4 ++-- doc/src/09020-changelog.md | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bin/domain/imag-timetrack/src/stop.rs b/bin/domain/imag-timetrack/src/stop.rs index 64979096..d0f17ea8 100644 --- a/bin/domain/imag-timetrack/src/stop.rs +++ b/bin/domain/imag-timetrack/src/stop.rs @@ -23,6 +23,7 @@ use filters::filter::Filter; use libimagerror::trace::trace_error; use libimagerror::iter::TraceIterator; +use libimagerror::trace::MapErrTrace; use libimagrt::runtime::Runtime; use libimagtimetrack::timetracking::TimeTracking; @@ -48,14 +49,30 @@ pub fn stop(rt: &Runtime) -> i32 { } }; - - // TODO: We do not yet support stopping all tags by simply calling the "stop" subcommand! - let tags : Vec = cmd.values_of("tags") - .unwrap() // enforced by clap - .map(String::from) - .map(TimeTrackingTag::from) - .collect(); + .map(|tags| tags.map(String::from).map(TimeTrackingTag::from).collect()) + .unwrap_or_else(|| { + // Get all timetrackings which do not have an end datetime. + rt.store() + .get_timetrackings() + .map_err_trace_exit_unwrap(1) + .filter_map(|tracking| { + let tracking = tracking.map_err_trace_exit_unwrap(1); + let is_none = tracking + .get_end_datetime() + .map_err_trace_exit_unwrap(1) + .is_none(); + + if is_none { + Some(tracking) + } else { + None + } + }) + .map(|t| t.get_timetrack_tag()) + .map(|r| r.map_err_trace_exit_unwrap(1)) + .collect() + }); let iter : GetTimeTrackIter = match rt.store().get_timetrackings() { Ok(i) => i, diff --git a/bin/domain/imag-timetrack/src/ui.rs b/bin/domain/imag-timetrack/src/ui.rs index cefcef86..7f3c4d47 100644 --- a/bin/domain/imag-timetrack/src/ui.rs +++ b/bin/domain/imag-timetrack/src/ui.rs @@ -67,11 +67,11 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .version("0.1") .arg(Arg::with_name("end-time") .index(1) - .required(true) + .required(false) .help("End-time when to stop the timetracking (use 'now' for current time)")) .arg(Arg::with_name("tags") .index(2) - .required(true) + .required(false) .multiple(true) .help("Tags to stop")) ) diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index bbce7b85..4756bc83 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -38,6 +38,7 @@ This section contains the changelog from the last release to the next release. * `libimagbookmark` does not longer wrap types from the store. * The `toml-query` dependency was updated to 0.5.0 * `imag-timetrack list` lists with a table now + * `imag-timetrack stop` now stops all runnings tags if none are specified * Bugfixes ## 0.5.0