summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-21 22:28:50 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-01-28 20:51:20 +0100
commit53bf1a513b81cf85e132005219f6370f119bea84 (patch)
tree7574cebd3f819f5956b33fd8cbdf0b9b9d5549d3 /bin
parent3735fbac2f68729bf5c855636179e6f3ea038f5d (diff)
Implement stopping all tags which are started
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-timetrack/src/stop.rs31
-rw-r--r--bin/domain/imag-timetrack/src/ui.rs4
2 files changed, 26 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<TimeTrackingTag> = 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"))
)