imag-todo: Use Err/Ok utils to map

This commit is contained in:
Matthias Beyer 2016-09-06 11:13:08 +02:00
parent 23a42dcb0d
commit b9a9fd52c4

View file

@ -13,7 +13,6 @@ extern crate libimagstore;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagtodo; extern crate libimagtodo;
use std::process::exit;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::io::stdin; use std::io::stdin;
@ -22,7 +21,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 libimagtodo::task::Task; use libimagtodo::task::Task;
use libimagerror::trace::trace_error; use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit};
mod ui; mod ui;
@ -51,18 +50,13 @@ fn tw_hook(rt: &Runtime) {
match Task::import(rt.store(), stdin) { match Task::import(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) => { Err(e) => trace_error_exit(&e, 1),
trace_error(&e);
exit(1);
}
} }
} else if subcmd.is_present("delete") { } else if subcmd.is_present("delete") {
// 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()) Task::delete_by_imports(rt.store(), stdin.lock()).map_err_trace().ok();
.map_err(|e| trace_error(&e))
.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
@ -120,8 +114,6 @@ fn list(rt: &Runtime) {
println!("{}", outstring); println!("{}", outstring);
}); });
if let Err(e) = res { res.map_err_trace().ok();
trace_error(&e);
}
} }