Implement stopping all tags which are started

This commit is contained in:
Matthias Beyer 2018-01-21 22:28:50 +01:00
parent 3735fbac2f
commit 53bf1a513b
3 changed files with 27 additions and 9 deletions

View file

@ -23,6 +23,7 @@ use filters::filter::Filter;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagerror::trace::MapErrTrace;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagtimetrack::timetracking::TimeTracking; 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") let tags : Vec<TimeTrackingTag> = cmd.values_of("tags")
.unwrap() // enforced by clap .map(|tags| tags.map(String::from).map(TimeTrackingTag::from).collect())
.map(String::from) .unwrap_or_else(|| {
.map(TimeTrackingTag::from) // Get all timetrackings which do not have an end datetime.
.collect(); 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() { let iter : GetTimeTrackIter = match rt.store().get_timetrackings() {
Ok(i) => i, Ok(i) => i,

View file

@ -67,11 +67,11 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.version("0.1") .version("0.1")
.arg(Arg::with_name("end-time") .arg(Arg::with_name("end-time")
.index(1) .index(1)
.required(true) .required(false)
.help("End-time when to stop the timetracking (use 'now' for current time)")) .help("End-time when to stop the timetracking (use 'now' for current time)"))
.arg(Arg::with_name("tags") .arg(Arg::with_name("tags")
.index(2) .index(2)
.required(true) .required(false)
.multiple(true) .multiple(true)
.help("Tags to stop")) .help("Tags to stop"))
) )

View file

@ -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. * `libimagbookmark` does not longer wrap types from the store.
* The `toml-query` dependency was updated to 0.5.0 * The `toml-query` dependency was updated to 0.5.0
* `imag-timetrack list` lists with a table now * `imag-timetrack list` lists with a table now
* `imag-timetrack stop` now stops all runnings tags if none are specified
* Bugfixes * Bugfixes
## 0.5.0 ## 0.5.0