Optimize implementation: Less matches

This patch simplifies the code to be not three nested matches but rather
one match and then some function chaining.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-11-04 22:36:35 +01:00
parent 1321f49428
commit 17913ae3fd
1 changed files with 11 additions and 14 deletions

View File

@ -69,6 +69,7 @@ use libimagstore::store::FileLockEntry;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreId;
use libimaginteraction::ask::ask_bool; use libimaginteraction::ask::ask_bool;
use libimagutil::debug_result::DebugResult;
mod ui; mod ui;
@ -115,20 +116,16 @@ fn create(rt: &Runtime) {
let date = scmd.value_of("create-date").unwrap(); // safe by clap let date = scmd.value_of("create-date").unwrap(); // safe by clap
let parsedate = |d, pname| match kairos_parse(d).map_err_trace_exit_unwrap(1) { let parsedate = |d, pname| match kairos_parse(d).map_err_trace_exit_unwrap(1) {
Parsed::TimeType(tt) => match tt.calculate() { Parsed::TimeType(tt) => tt.calculate()
Ok(tt) => match tt.get_moment() { .map_dbg(|y| format!("TimeType yielded: '{:?}'", y))
Some(mom) => mom.date(), .map_err_trace_exit_unwrap(1)
None => { .get_moment()
debug!("TimeType yielded: '{:?}'", tt); .ok_or_else(|| {
error!("Error: '{}' parameter does not yield a point in time", pname); error!("Error: '{}' parameter does not yield a point in time", pname);
exit(1); exit(1)
}, })
}, .unwrap() // safe by above
Err(e) => { .date(),
error!("Error: '{:?}'", e);
exit(1);
}
},
_ => { _ => {
error!("Error: '{}' parameter does not yield a point in time", pname); error!("Error: '{}' parameter does not yield a point in time", pname);
exit(1); exit(1);