implemented add-hook
This commit is contained in:
parent
4b8bf877c1
commit
7de2577725
3 changed files with 64 additions and 19 deletions
|
@ -1,19 +1,29 @@
|
|||
extern crate clap;
|
||||
extern crate glob;
|
||||
extern crate task_hookrs;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate serde_json;
|
||||
extern crate semver;
|
||||
extern crate toml;
|
||||
#[macro_use] extern crate version;
|
||||
|
||||
extern crate task_hookrs;
|
||||
|
||||
extern crate libimagrt;
|
||||
extern crate libimagstore;
|
||||
extern crate libimagutil;
|
||||
extern crate libimagtodo;
|
||||
|
||||
use std::process::exit;
|
||||
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 libimagtodo::task::Task;
|
||||
use libimagtodo::task::IntoTask;
|
||||
use libimagutil::trace::trace_error;
|
||||
|
||||
mod ui;
|
||||
|
||||
|
@ -24,7 +34,7 @@ fn main() {
|
|||
let version = &version!()[..];
|
||||
let about = "Interface with taskwarrior";
|
||||
let ui = build_ui(Runtime::get_default_cli_builder(name, version, about));
|
||||
|
||||
|
||||
let rt = {
|
||||
let rt = Runtime::new(ui);
|
||||
if rt.is_ok() {
|
||||
|
@ -36,20 +46,32 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
let scmd = rt.cli().subcommand_name();
|
||||
match scmd {
|
||||
Some("tw-hook") => {
|
||||
let subcmd = rt.cli().subcommand_matches("tw-hook").unwrap();
|
||||
if subcmd.is_present("add") {
|
||||
println!("To be implemented");
|
||||
//
|
||||
// TODO @Kevin: import function aus task_hookrs benutzen, um
|
||||
// stdin auszulesen, und dann auf dem
|
||||
// task_hookrs::task::Task den Trait für die
|
||||
// Umwandlung aufrufen.
|
||||
//
|
||||
if let Ok(ttasks) = task_hookrs::import::import(stdin()) {
|
||||
for ttask in ttasks {
|
||||
println!("{}", match serde_json::ser::to_string(&ttask) {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
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") {
|
||||
println!("To be implemented");
|
||||
|
@ -73,7 +95,7 @@ fn main() {
|
|||
let mut tw_process = Command::new("task").stdin(Stdio::null()).args(&args).spawn().unwrap_or_else(|e| {
|
||||
panic!("failed to execute taskwarrior: {}", e);
|
||||
});
|
||||
|
||||
|
||||
let output = tw_process.wait_with_output().unwrap_or_else(|e| {
|
||||
panic!("failed to unwrap output: {}", e);
|
||||
});
|
||||
|
@ -87,6 +109,6 @@ fn main() {
|
|||
},
|
||||
_ => panic!("Reached unreachable Code"),
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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 } )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue