diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-08-06 11:39:31 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-08-06 11:39:31 +0200 |
commit | 0fd8b3b286f42cccfa5728b13de2070a9252d35c (patch) | |
tree | 1fdac734f5e906f83366c2507ba948ede4dbaf15 /imag-todo | |
parent | 6222aac83774ac3da2ca5c0e9cf892e359839beb (diff) |
Move deletion logic into lib
Diffstat (limited to 'imag-todo')
-rw-r--r-- | imag-todo/src/main.rs | 41 |
1 files changed, 3 insertions, 38 deletions
diff --git a/imag-todo/src/main.rs b/imag-todo/src/main.rs index dae6a34d..d5149ad8 100644 --- a/imag-todo/src/main.rs +++ b/imag-todo/src/main.rs @@ -60,44 +60,9 @@ fn tw_hook(rt: &Runtime) { // The used hook is "on-modify". This hook gives two json-objects // per usage und wants one (the second one) back. let stdin = stdin(); - let stdin = stdin.lock(); - - match import_tasks(stdin) { - Ok(ttasks) => for (counter, ttask) in ttasks.iter().enumerate() { - if counter % 2 == 1 { - // Only every second task is needed, the first one is the - // task before the change, and the second one after - // the change. The (maybe modified) second one is - // expected by taskwarrior. - match serde_json::ser::to_string(&ttask) { - Ok(val) => println!("{}", val), - Err(e) => { - trace_error(&e); - exit(1); - } - } - - // Taskwarrior does not have the concept of deleted tasks, but only modified - // ones. - // - // Here we check if the status of a task is deleted and if yes, we delete it - // from the store. - if *ttask.status() == TaskStatus::Deleted { - match Task::delete_by_uuid(rt.store(), *ttask.uuid()) { - Ok(_) => println!("Deleted task {}", *ttask.uuid()), - Err(e) => { - trace_error(&e); - exit(1); - } - } - } - } // end if c % 2 - }, - Err(e) => { - trace_error(&e); - exit(1); - }, - } + Task::delete_by_imports(rt.store(), stdin.lock()) + .map_err(|e| trace_error(&e)) + .ok(); } else { // Should not be possible, as one argument is required via // ArgGroup |