Remove calls to exit() and replace them with error propagation up to main()

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-19 08:54:57 +02:00
parent 647ca2fea6
commit 6ab5d1d880

View file

@ -36,21 +36,19 @@
extern crate clap; extern crate clap;
extern crate failure; extern crate failure;
#[macro_use] extern crate log;
extern crate libimagerror; extern crate libimagerror;
extern crate libimagrt; extern crate libimagrt;
extern crate libimagstore; extern crate libimagstore;
use failure::Fallible as Result; use failure::Fallible as Result;
use failure::err_msg;
use clap::App; use clap::App;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication; use libimagrt::application::ImagApplication;
use libimagerror::trace::MapErrTrace;
use libimagstore::iter::create::StoreIdCreateIteratorExtension; use libimagstore::iter::create::StoreIdCreateIteratorExtension;
use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension; use libimagstore::iter::retrieve::StoreIdRetrieveIteratorExtension;
use libimagerror::exit::ExitUnwrap;
mod ui; mod ui;
@ -60,30 +58,17 @@ pub enum ImagCreate {}
impl ImagApplication for ImagCreate { impl ImagApplication for ImagCreate {
fn run(rt: Runtime) -> Result<()> { fn run(rt: Runtime) -> Result<()> {
let force = rt.cli().is_present("force"); let force = rt.cli().is_present("force");
debug!("Detected force = {}", force);
let ids = rt.ids::<crate::ui::PathProvider>() let ids = rt.ids::<crate::ui::PathProvider>()?
.map_err_trace_exit_unwrap() .ok_or_else(|| err_msg("No ids supplied"))?
.unwrap_or_else(|| {
error!("No ids supplied");
::std::process::exit(1);
})
.into_iter() .into_iter()
.map(|id| { debug!("id = {}", id); id })
.map(Ok); .map(Ok);
if force { if force {
ids.into_retrieve_iter(rt.store()).collect::<Result<Vec<_>>>() ids.into_retrieve_iter(rt.store()).collect::<Result<Vec<_>>>()
} else { } else {
ids.into_create_iter(rt.store()).collect::<Result<Vec<_>>>() ids.into_create_iter(rt.store()).collect::<Result<Vec<_>>>()
}.map_err_trace_exit_unwrap() }.map(|_| ())
.into_iter()
.for_each(|el| {
rt.report_touched(el.get_location()).unwrap_or_exit();
trace!("Entry = {}", el.get_location());
});
Ok(())
} }
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> { fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {