Merge pull request #16 from matthiasbeyer/libimagtodo/more-cleanup
Libimagtodo/more cleanup
This commit is contained in:
commit
84d05a10c0
4 changed files with 44 additions and 38 deletions
|
@ -60,44 +60,9 @@ 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();
|
||||||
let stdin = stdin.lock();
|
Task::delete_by_imports(rt.store(), stdin.lock())
|
||||||
|
.map_err(|e| trace_error(&e))
|
||||||
match import_tasks(stdin) {
|
.ok();
|
||||||
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);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Should not be possible, as one argument is required via
|
// Should not be possible, as one argument is required via
|
||||||
// ArgGroup
|
// ArgGroup
|
||||||
|
|
|
@ -8,6 +8,8 @@ semver = "0.2"
|
||||||
task-hookrs = "0.2"
|
task-hookrs = "0.2"
|
||||||
uuid = "0.2.0"
|
uuid = "0.2.0"
|
||||||
toml = "0.1.28"
|
toml = "0.1.28"
|
||||||
|
log = "0.3.6"
|
||||||
|
serde_json = "0.7.3"
|
||||||
|
|
||||||
[dependencies.libimagstore]
|
[dependencies.libimagstore]
|
||||||
path = "../libimagstore"
|
path = "../libimagstore"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
|
#[macro_use] extern crate log;
|
||||||
|
extern crate serde_json;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagerror;
|
#[macro_use] extern crate libimagerror;
|
||||||
|
|
|
@ -100,6 +100,43 @@ impl<'a> Task<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_by_imports<R: BufRead>(store: &Store, r: R) -> Result<()> {
|
||||||
|
use serde_json::ser::to_string as serde_to_string;
|
||||||
|
use task_hookrs::status::TaskStatus;
|
||||||
|
|
||||||
|
for (counter, res_ttask) in import_tasks(r).into_iter().enumerate() {
|
||||||
|
match res_ttask {
|
||||||
|
Ok(ttask) => {
|
||||||
|
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_to_string(&ttask).map_err_into(TodoErrorKind::ImportError) {
|
||||||
|
// use println!() here, as we talk with TW
|
||||||
|
Ok(val) => println!("{}", val),
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(store, *ttask.uuid()) {
|
||||||
|
Ok(_) => info!("Deleted task {}", *ttask.uuid()),
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // end if c % 2
|
||||||
|
},
|
||||||
|
Err(e) => return Err(e).map_err_into(TodoErrorKind::ImportError),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delete_by_uuid(store: &Store, uuid: Uuid) -> Result<()> {
|
pub fn delete_by_uuid(store: &Store, uuid: Uuid) -> Result<()> {
|
||||||
store.delete(ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid())
|
store.delete(ModuleEntryPath::new(format!("taskwarrior/{}", uuid)).into_storeid())
|
||||||
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
.map_err(|e| TodoError::new(TodoErrorKind::StoreError, Some(Box::new(e))))
|
||||||
|
|
Loading…
Reference in a new issue