implemented add-hook

This commit is contained in:
mario 2016-06-28 20:13:11 +02:00
parent 4b8bf877c1
commit 7de2577725
3 changed files with 64 additions and 19 deletions

View file

@ -1,19 +1,29 @@
extern crate clap; extern crate clap;
extern crate glob; extern crate glob;
extern crate task_hookrs;
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate serde_json;
extern crate semver; extern crate semver;
extern crate toml; extern crate toml;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate task_hookrs;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagutil; extern crate libimagutil;
extern crate libimagtodo;
use std::process::exit; use std::process::exit;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::io::stdin;
use task_hookrs::import::import;
use task_hookrs::task::Task as TTask;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagtodo::task::Task;
use libimagtodo::task::IntoTask;
use libimagutil::trace::trace_error;
mod ui; mod ui;
@ -43,13 +53,25 @@ fn main() {
Some("tw-hook") => { Some("tw-hook") => {
let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap(); let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap();
if subcmd.is_present("add") { if subcmd.is_present("add") {
println!("To be implemented"); if let Ok(ttasks) = task_hookrs::import::import(stdin()) {
// for ttask in ttasks {
// TODO @Kevin: import function aus task_hookrs benutzen, um println!("{}", match serde_json::ser::to_string(&ttask) {
// stdin auszulesen, und dann auf dem Ok(val) => val,
// task_hookrs::task::Task den Trait für die Err(e) => {
// Umwandlung aufrufen. error!("{}", e);
// return;
}
});
let task = match ttask.into_filelockentry(rt.store()) {
Ok(val) => val,
Err(e) => {
trace_error(&e);
error!("{}", e);
return;
}
};
}
}
} }
else if subcmd.is_present("delete") { else if subcmd.is_present("delete") {
println!("To be implemented"); println!("To be implemented");

View file

@ -5,7 +5,7 @@ authors = ["mario <mario-krehl@gmx.de>"]
[dependencies] [dependencies]
semver = "0.2" semver = "0.2"
task-hookrs = { git = "https://github.com/matthiasbeyer/task-hookrs.git" } task-hookrs = "0.1.0"
uuid = "0.2.0" uuid = "0.2.0"
toml = "0.1.28" toml = "0.1.28"

View file

@ -1,4 +1,5 @@
use std::ops::Deref; use std::ops::Deref;
use std::collections::BTreeMap;
use toml::Value; use toml::Value;
use task_hookrs::task::Task as TTask; use task_hookrs::task::Task as TTask;
@ -49,13 +50,35 @@ impl<'a> IntoTask<'a> for TTask {
let uuid = self.uuid(); let uuid = self.uuid();
let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid(); let store_id = ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid();
match store.retrieve(store_id) { match store.retrieve(store_id) {
Err(e) => Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e)))), Err(e) => {
Ok(mut fle) => { return Err(TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
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 })
}
}, },
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 } )
}
} }
} }
} }