imag-store: Use Err/Ok Result map utils to refactor code
This commit is contained in:
parent
a39f07f9a5
commit
daca530dd5
2 changed files with 11 additions and 15 deletions
|
@ -1,13 +1,12 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::trace_error_exit;
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagstore::storeid::StoreId;
|
||||
use libimagutil::warn_exit::warn_exit;
|
||||
use libimagutil::warn_result::*;
|
||||
|
||||
pub fn delete(rt: &Runtime) {
|
||||
use std::process::exit;
|
||||
|
||||
rt.cli()
|
||||
.subcommand_matches("delete")
|
||||
.map(|sub| {
|
||||
|
@ -15,15 +14,13 @@ pub fn delete(rt: &Runtime) {
|
|||
.map(|id| {
|
||||
let path = PathBuf::from(id);
|
||||
let path = try!(StoreId::new(Some(rt.store().path().clone()), path)
|
||||
.map_err(|e| trace_error_exit(&e, 1)));
|
||||
.map_err_trace_exit(1));
|
||||
debug!("Deleting file at {:?}", id);
|
||||
|
||||
rt.store()
|
||||
.delete(path)
|
||||
.map_err(|e| {
|
||||
warn!("Error: {:?}", e);
|
||||
exit(1);
|
||||
})
|
||||
.map_warn_err(|e| format!("Error: {:?}", e))
|
||||
.map_err_trace_exit(1)
|
||||
})
|
||||
.or_else(|| warn_exit("No ID passed. Will exit now", 1))
|
||||
})
|
||||
|
|
|
@ -6,7 +6,8 @@ use toml::Value;
|
|||
use libimagstore::store::FileLockEntry;
|
||||
use libimagstore::storeid::StoreId;
|
||||
use libimagrt::runtime::Runtime;
|
||||
use libimagerror::trace::{trace_error, trace_error_exit};
|
||||
use libimagerror::trace::MapErrTrace;
|
||||
use libimagutil::debug_result::*;
|
||||
|
||||
pub fn retrieve(rt: &Runtime) {
|
||||
rt.cli()
|
||||
|
@ -16,18 +17,16 @@ pub fn retrieve(rt: &Runtime) {
|
|||
.map(|id| {
|
||||
let path = PathBuf::from(id);
|
||||
let path = try!(StoreId::new(Some(rt.store().path().clone()), path)
|
||||
.map_err(|e| trace_error_exit(&e, 1)));
|
||||
.map_err_trace_exit(1));
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
rt.store()
|
||||
// "id" must be present, enforced via clap spec
|
||||
.retrieve(path)
|
||||
.map(|e| print_entry(rt, scmd, e))
|
||||
.map_err(|e| {
|
||||
debug!("No entry.");
|
||||
debug!("{}:", e);
|
||||
trace_error(&e);
|
||||
})
|
||||
.map_dbg_str("No entry")
|
||||
.map_dbg(|e| format!("{:?}", e))
|
||||
.map_err_trace()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue