imag-diary: Use util fn warn_exit()

This commit is contained in:
Matthias Beyer 2016-09-05 19:30:21 +02:00
parent ac5ee9fb51
commit 19711219e7
5 changed files with 14 additions and 36 deletions

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");