diff options
author | mario <mario-krehl@gmx.de> | 2016-06-28 20:13:11 +0200 |
---|---|---|
committer | mario <mario-krehl@gmx.de> | 2016-06-28 20:13:11 +0200 |
commit | 7de2577725a27635491dfc7d83787bfc9dccd64f (patch) | |
tree | 83a73409cb7e4d27633dc5997a4d4e4a5027d762 /libimagtodo | |
parent | 4b8bf877c1c2f3c228ff60bb6de89dc469cbbc34 (diff) |
implemented add-hook
Diffstat (limited to 'libimagtodo')
-rw-r--r-- | libimagtodo/Cargo.toml | 2 | ||||
-rw-r--r-- | libimagtodo/src/task.rs | 35 |
2 files changed, 30 insertions, 7 deletions
diff --git a/libimagtodo/Cargo.toml b/libimagtodo/Cargo.toml index dc1f6d8b..25e6386e 100644 --- a/libimagtodo/Cargo.toml +++ b/libimagtodo/Cargo.toml @@ -5,7 +5,7 @@ authors = ["mario <mario-krehl@gmx.de>"] [dependencies] semver = "0.2" -task-hookrs = { git = "https://github.com/matthiasbeyer/task-hookrs.git" } +task-hookrs = "0.1.0" uuid = "0.2.0" toml = "0.1.28" diff --git a/libimagtodo/src/task.rs b/libimagtodo/src/task.rs index 8c3b0886..e8384a73 100644 --- a/libimagtodo/src/task.rs +++ b/libimagtodo/src/task.rs @@ -1,4 +1,5 @@ use std::ops::Deref; +use std::collections::BTreeMap; use toml::Value; use task_hookrs::task::Task as TTask; @@ -49,13 +50,35 @@ impl<'a> IntoTask<'a> for TTask { let uuid = self.uuid(); let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); match store.retrieve(store_id) { - Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), - Ok(mut fle) => { - match fle.get_header_mut().set("todo.uuid", Value::String(format!("{}", uuid))) { - Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), - Ok(_) => Ok(Task { flentry : fle }) - } + Err(e) => { + return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) }, + Ok(mut fle) => { + { + let mut header = fle.get_header_mut(); + match header.read("todo") { + Ok(None) => { + match header.set("todo", Value::Table(BTreeMap::new())) { + Ok(_) => { }, + Err(e) => { + return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) + } + } + } + Ok(Some(_)) => { } + Err(e) => { + } + } + match header.set("todo.uuid", Value::String(format!("{}",uuid))) { + Ok(_) => { }, + Err(e) => { + return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))) + } + } + } + // If none of the errors above have returned the function, everything is fine + Ok(Task { flentry : fle } ) + } } } } |