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:
parent
0e20b25091
commit
fd40715b29
2 changed files with 17 additions and 31 deletions
|
@ -25,6 +25,7 @@ version = "3.0.0"
|
||||||
toml = "0.5.1"
|
toml = "0.5.1"
|
||||||
toml-query = "0.9.2"
|
toml-query = "0.9.2"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
|
resiter = "0.3.0"
|
||||||
|
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
extern crate resiter;
|
||||||
|
|
||||||
extern crate libimagentryedit;
|
extern crate libimagentryedit;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
@ -44,16 +45,16 @@ extern crate libimagrt;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagutil;
|
extern crate libimagutil;
|
||||||
|
|
||||||
use libimagerror::trace::MapErrTrace;
|
|
||||||
use libimagerror::iter::TraceIterator;
|
|
||||||
use libimagentryedit::edit::Edit;
|
use libimagentryedit::edit::Edit;
|
||||||
use libimagentryedit::edit::EditHeader;
|
use libimagentryedit::edit::EditHeader;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::application::ImagApplication;
|
use libimagrt::application::ImagApplication;
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
|
||||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
|
use libimagerror::iter::IterInnerOkOrElse;
|
||||||
|
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
use failure::err_msg;
|
||||||
|
use resiter::AndThen;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
@ -68,39 +69,23 @@ impl ImagApplication for ImagEdit {
|
||||||
let edit_header = rt.cli().is_present("edit-header");
|
let edit_header = rt.cli().is_present("edit-header");
|
||||||
let edit_header_only = rt.cli().is_present("edit-header-only");
|
let edit_header_only = rt.cli().is_present("edit-header-only");
|
||||||
|
|
||||||
let sids = rt
|
rt.ids::<crate::ui::PathProvider>()?
|
||||||
.ids::<crate::ui::PathProvider>()
|
.ok_or_else(|| err_msg("No ids supplied"))?
|
||||||
.map_err_trace_exit_unwrap()
|
.into_iter()
|
||||||
.unwrap_or_else(|| {
|
.map(Ok)
|
||||||
error!("No ids supplied");
|
|
||||||
::std::process::exit(1);
|
|
||||||
})
|
|
||||||
.into_iter();
|
|
||||||
|
|
||||||
StoreIdIterator::new(Box::new(sids.into_iter().map(Ok)))
|
|
||||||
.into_get_iter(rt.store())
|
.into_get_iter(rt.store())
|
||||||
.trace_unwrap_exit()
|
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
|
||||||
.map(|o| o.unwrap_or_else(|| {
|
.inspect(|e| debug!("Editing = {:?}", e))
|
||||||
error!("Did not find one entry");
|
.and_then_ok(|mut entry| {
|
||||||
::std::process::exit(1)
|
|
||||||
}))
|
|
||||||
.for_each(|mut entry| {
|
|
||||||
if edit_header {
|
if edit_header {
|
||||||
let _ = entry
|
entry.edit_header_and_content(&rt)
|
||||||
.edit_header_and_content(&rt)
|
|
||||||
.map_err_trace_exit_unwrap();
|
|
||||||
} else if edit_header_only {
|
} else if edit_header_only {
|
||||||
let _ = entry
|
entry.edit_header(&rt)
|
||||||
.edit_header(&rt)
|
|
||||||
.map_err_trace_exit_unwrap();
|
|
||||||
} else {
|
} else {
|
||||||
let _ = entry
|
entry.edit_content(&rt)
|
||||||
.edit_content(&rt)
|
|
||||||
.map_err_trace_exit_unwrap();
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.collect()
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
|
|
Loading…
Reference in a new issue