Refactor imag-todo to work with the changes in libimagtodo

This commit is contained in:
Mario Krehl 2017-09-02 13:29:49 +02:00
parent f3bb6d02d0
commit ef92acb1b0
2 changed files with 29 additions and 22 deletions

View file

@ -22,5 +22,6 @@ is-match = "0.1.*"
version = "2.0.1" version = "2.0.1"
libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" }
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
libimagtodo = { version = "0.4.0", path = "../../../lib/domain/libimagtodo" } libimagtodo = { version = "0.4.0", path = "../../../lib/domain/libimagtodo" }

View file

@ -25,6 +25,7 @@ extern crate toml_query;
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagtodo; extern crate libimagtodo;
@ -35,6 +36,7 @@ use toml::Value;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagstore::store::FileLockEntry;
use libimagtodo::task::Task; use libimagtodo::task::Task;
use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit}; use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
@ -61,9 +63,9 @@ fn tw_hook(rt: &Runtime) {
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") {
let stdin = stdin(); let stdin = stdin();
let stdin = stdin.lock(); // implements BufRead which is required for `Task::import()` let stdin = stdin.lock(); // implements BufRead which is required for `FileLockEntry::import_task_from_reader()`
match Task::import(rt.store(), stdin) { match FileLockEntry::import_task_from_reader(rt.store(), stdin) {
Ok((_, line, uuid)) => println!("{}\nTask {} stored in imag", line, uuid), Ok((_, line, uuid)) => println!("{}\nTask {} stored in imag", line, uuid),
Err(e) => trace_error_exit(&e, 1), Err(e) => trace_error_exit(&e, 1),
} }
@ -71,7 +73,7 @@ fn tw_hook(rt: &Runtime) {
// The used hook is "on-modify". This hook gives two json-objects // The used hook is "on-modify". This hook gives two json-objects
// per usage und wants one (the second one) back. // per usage und wants one (the second one) back.
let stdin = stdin(); let stdin = stdin();
Task::delete_by_imports(rt.store(), stdin.lock()).map_err_trace().ok(); FileLockEntry::delete_tasks_by_imports(rt.store(), stdin.lock()).map_err_trace().ok();
} else { } else {
// Should not be possible, as one argument is required via // Should not be possible, as one argument is required via
// ArgGroup // ArgGroup
@ -92,30 +94,34 @@ fn list(rt: &Runtime) {
is_match!(e.kind(), &::toml_query::error::ErrorKind::IdentifierNotFoundInDocument(_)) is_match!(e.kind(), &::toml_query::error::ErrorKind::IdentifierNotFoundInDocument(_))
}; };
let res = Task::all(rt.store()) // get all tasks let res = FileLockEntry::all_tasks(rt.store()) // get all tasks
.map(|iter| { // and if this succeeded .map(|iter| { // and if this succeeded
// filter out the ones were we can read the uuid // filter out the ones were we can read the uuid
let uuids : Vec<_> = iter.filter_map(|t| match t { let uuids : Vec<_> = iter.filter_map(|storeid| {
Ok(v) => match v.get_header().read(&String::from("todo.uuid")) { match rt.store().retrieve(storeid) {
Ok(Some(&Value::String(ref u))) => Some(u.clone()), Ok(fle) => {
Ok(Some(_)) => { match fle.get_header().read(&String::from("todo.uuid")) {
warn!("Header type error"); Ok(Some(&Value::String(ref u))) => Some(u.clone()),
None Ok(Some(_)) => {
}, warn!("Header type error");
Ok(None) => { None
warn!("Header missing field"); },
None Ok(None) => {
warn!("Header missing field");
None
},
Err(e) => {
if !no_identifier(&e) {
trace_error(&e);
}
None
}
}
}, },
Err(e) => { Err(e) => {
if !no_identifier(&e) { trace_error(&e);
trace_error(&e);
}
None None
} },
},
Err(e) => {
trace_error(&e);
None
} }
}) })
.collect(); .collect();