Merge pull request #713 from matthiasbeyer/use-warn-exit-helper

Use warn exit helper
This commit is contained in:
Matthias Beyer 2016-09-08 10:56:13 +02:00 committed by GitHub
commit 712d666ce6
11 changed files with 32 additions and 65 deletions

View file

@ -10,6 +10,7 @@ use libimagcounter::counter::Counter;
use libimagcounter::error::CounterError;
use libimagrt::runtime::Runtime;
use libimagutil::key_value_split::IntoKeyValue;
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::{trace_error, trace_error_exit};
type Result<T> = RResult<T, CounterError>;
@ -17,8 +18,7 @@ type Result<T> = RResult<T, CounterError>;
pub fn interactive(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("interactive");
if scmd.is_none() {
debug!("No subcommand");
exit(1);
warn_exit("No subcommand", 1);
}
let scmd = scmd.unwrap();
debug!("Found 'interactive' command");
@ -130,8 +130,7 @@ impl<'a> Display for Binding<'a> {
fn compute_pair<'a>(rt: &'a Runtime, spec: &str) -> Result<(char, Binding<'a>)> {
let kv = String::from(spec).into_kv();
if kv.is_none() {
debug!("Key-Value parsing failed!");
exit(1);
warn_exit("Key-Value parsing failed!", 1);
}
let kv = kv.unwrap();

View file

@ -9,15 +9,13 @@ use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
use libimagdiary::entry::Entry;
use libimagdiary::result::Result;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn create(rt: &Runtime) {
let diaryname = get_diary_name(rt)
.unwrap_or_else(|| {
warn!("No diary selected. Use either the configuration file or the commandline option");
exit(1)
});
.unwrap_or_else( || warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
let prevent_edit = rt.cli().subcommand_matches("create").unwrap().is_present("no-edit");
@ -78,10 +76,7 @@ pub fn create(rt: &Runtime) {
exit(1);
},
None => {
warn!("Unexpected error, cannot continue");
exit(1);
},
None => warn_exit("Unexpected error, cannot continue", 1)
};
diary.new_entry_by_id(id)

View file

@ -1,4 +1,3 @@
use std::process::exit;
use chrono::naive::datetime::NaiveDateTime;
use libimagdiary::diary::Diary;
@ -7,16 +6,15 @@ use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
use libimagtimeui::datetime::DateTime;
use libimagtimeui::parse::Parse;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn delete(rt: &Runtime) {
use libimaginteraction::ask::ask_bool;
let diaryname = get_diary_name(rt).unwrap_or_else(|| {
warn!("No diary selected. Use either the configuration file or the commandline option");
exit(1);
});
let diaryname = get_diary_name(rt)
.unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
let diary = Diary::open(rt.store(), &diaryname[..]);
debug!("Diary opened: {:?}", diary);
@ -39,10 +37,7 @@ pub fn delete(rt: &Runtime) {
Some(Ok(e)) => e,
Some(Err(e)) => trace_error_exit(&e, 1),
None => {
warn!("No entry");
exit(1);
},
None => warn_exit("No entry", 1)
};
if !ask_bool(&format!("Deleting {:?}", to_del.get_location())[..], Some(true)) {

View file

@ -1,4 +1,3 @@
use std::process::exit;
use chrono::naive::datetime::NaiveDateTime;
use libimagdiary::diary::Diary;
@ -11,15 +10,12 @@ use libimagerror::trace::trace_error;
use libimagerror::into::IntoError;
use libimagtimeui::datetime::DateTime;
use libimagtimeui::parse::Parse;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn edit(rt: &Runtime) {
let diaryname = get_diary_name(rt).unwrap_or_else(|| {
warn!("No diary name");
exit(1);
});
let diaryname = get_diary_name(rt).unwrap_or_else(|| warn_exit("No diary name", 1));
let diary = Diary::open(rt.store(), &diaryname[..]);
let datetime : Option<NaiveDateTime> = rt

View file

@ -1,5 +1,3 @@
use std::process::exit;
use libimagdiary::diary::Diary;
use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::MapErrInto;
@ -8,14 +6,13 @@ use libimagentrylist::lister::Lister;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use libimagerror::trace::trace_error;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn list(rt: &Runtime) {
let diaryname = get_diary_name(rt).unwrap_or_else(|| {
warn!("No diary selected. Use either the configuration file or the commandline option");
exit(1);
});
let diaryname = get_diary_name(rt)
.unwrap_or_else(|| warn_exit("No diary selected. Use either the configuration file or the commandline option", 1));
fn entry_to_location_listing_string(e: &Entry) -> String {
e.get_location().clone()

View file

@ -1,19 +1,14 @@
use std::process::exit;
use libimagdiary::diary::Diary;
use libimagentryview::viewer::Viewer;
use libimagentryview::builtin::plain::PlainViewer;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error;
use libimagutil::warn_exit::warn_exit;
use util::get_diary_name;
pub fn view(rt: &Runtime) {
let diaryname = get_diary_name(rt).unwrap_or_else(|| {
warn!("No diary name");
exit(1);
});
let diaryname = get_diary_name(rt).unwrap_or_else(|| warn_exit("No diary name", 1));
let diary = Diary::open(rt.store(), &diaryname[..]);
let show_header = rt.cli().subcommand_matches("view").unwrap().is_present("show-header");

View file

@ -26,7 +26,6 @@ extern crate libimagstore;
extern crate libimagerror;
extern crate libimagutil;
use std::process::exit;
use std::ops::Deref;
use libimagrt::runtime::Runtime;
@ -38,6 +37,7 @@ use libimagstore::store::Store;
use libimagerror::trace::{trace_error, trace_error_exit};
use libimagentrylink::external::ExternalLinker;
use libimagutil::warn_result::*;
use libimagutil::warn_exit::warn_exit;
use clap::ArgMatches;
use url::Url;
@ -57,10 +57,7 @@ fn main() {
match name {
"internal" => handle_internal_linking(&rt),
"external" => handle_external_linking(&rt),
_ => {
warn!("No commandline call");
exit(1);
},
_ => warn_exit("No commandline call", 1)
}
});
}
@ -112,8 +109,7 @@ fn handle_internal_linking(rt: &Runtime) {
let mut from = {
let from = get_from_entry(&rt);
if from.is_none() {
warn!("No 'from' entry");
exit(1);
warn_exit("No 'from' entry", 1);
}
from.unwrap()
};
@ -122,8 +118,7 @@ fn handle_internal_linking(rt: &Runtime) {
let to = {
let to = get_to_entries(&rt);
if to.is_none() {
warn!("No 'to' entry");
exit(1);
warn_exit("No 'to' entry", 1);
}
to.unwrap()
};

View file

@ -3,6 +3,7 @@ use std::path::PathBuf;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
pub fn delete(rt: &Runtime) {
use std::process::exit;
@ -24,14 +25,8 @@ pub fn delete(rt: &Runtime) {
exit(1);
})
})
.or_else(|| {
warn!("No ID passed. Will exit now");
exit(1);
})
.or_else(|| warn_exit("No ID passed. Will exit now", 1))
})
.or_else(|| {
warn!("No subcommand 'delete'. Will exit now");
exit(1);
});
.or_else(|| warn_exit("No subcommand 'delete'. Will exit now", 1));
}

View file

@ -1,13 +1,11 @@
use std::process::exit;
use libimagrt::runtime::Runtime;
use libimagutil::warn_exit::warn_exit;
pub fn verify(rt: &Runtime) {
if rt.store().verify() {
info!("Store seems to be fine");
} else {
warn!("Store seems to be broken somehow");
exit(1);
warn_exit("Store seems to be broken somehow", 1);
}
}

View file

@ -22,3 +22,6 @@ path = "../libimagerror"
[dependencies.libimagentrytag]
path = "../libimagentrytag"
[dependencies.libimagutil]
path = "../libimagutil"

View file

@ -8,6 +8,7 @@ extern crate libimagstore;
extern crate libimagrt;
extern crate libimagentrytag;
extern crate libimagerror;
extern crate libimagutil;
use std::process::exit;
use std::path::PathBuf;
@ -19,6 +20,7 @@ use libimagentrytag::tag::Tag;
use libimagerror::trace::{trace_error, trace_error_exit};
use libimagentrytag::ui::{get_add_tags, get_remove_tags};
use libimagstore::storeid::StoreId;
use libimagutil::warn_exit::warn_exit;
mod ui;
@ -103,10 +105,7 @@ fn list(id: PathBuf, rt: &Runtime) {
let entry = match rt.store().get(path.clone()) {
Ok(Some(e)) => e,
Ok(None) => {
info!("No entry found.");
exit(1);
},
Ok(None) => warn_exit("No entry found.", 1),
Err(e) => {
warn!("Could not get entry '{:?}'", path);