From a200031eb1b52fd799c263abf57f9c5a76d09100 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 19:28:08 +0200 Subject: [PATCH 1/5] imag-counter: use util function warn_exit() --- imag-counter/src/interactive.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/imag-counter/src/interactive.rs b/imag-counter/src/interactive.rs index 4dbb810d..d37a0c05 100644 --- a/imag-counter/src/interactive.rs +++ b/imag-counter/src/interactive.rs @@ -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 = RResult; @@ -17,8 +18,7 @@ type Result = RResult; 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(); From ac5ee9fb518562fd52c561e0a2891fc9b975d72e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 19:29:06 +0200 Subject: [PATCH 2/5] imag-link: Use util function warn_exit() --- imag-link/src/main.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index fd8d9d5d..7f036e6e 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -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() }; From 19711219e76a24d7bee0be51d22f5ca012b1e2b9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 19:30:21 +0200 Subject: [PATCH 3/5] imag-diary: Use util fn warn_exit() --- imag-diary/src/create.rs | 11 +++-------- imag-diary/src/delete.rs | 13 ++++--------- imag-diary/src/edit.rs | 8 ++------ imag-diary/src/list.rs | 9 +++------ imag-diary/src/view.rs | 9 ++------- 5 files changed, 14 insertions(+), 36 deletions(-) diff --git a/imag-diary/src/create.rs b/imag-diary/src/create.rs index 66818527..c715cfaf 100644 --- a/imag-diary/src/create.rs +++ b/imag-diary/src/create.rs @@ -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) diff --git a/imag-diary/src/delete.rs b/imag-diary/src/delete.rs index d5fd75e7..aec5a8eb 100644 --- a/imag-diary/src/delete.rs +++ b/imag-diary/src/delete.rs @@ -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)) { diff --git a/imag-diary/src/edit.rs b/imag-diary/src/edit.rs index 7b79aa26..88dd5eef 100644 --- a/imag-diary/src/edit.rs +++ b/imag-diary/src/edit.rs @@ -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 = rt diff --git a/imag-diary/src/list.rs b/imag-diary/src/list.rs index 757cf3a1..72d2d5ab 100644 --- a/imag-diary/src/list.rs +++ b/imag-diary/src/list.rs @@ -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() diff --git a/imag-diary/src/view.rs b/imag-diary/src/view.rs index c214eafe..742bc262 100644 --- a/imag-diary/src/view.rs +++ b/imag-diary/src/view.rs @@ -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"); From c91de877d018ac11a475d35649504678d41c6fc8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 19:33:39 +0200 Subject: [PATCH 4/5] imag-tag: Use util fn warn_exit() --- imag-tag/Cargo.toml | 3 +++ imag-tag/src/main.rs | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/imag-tag/Cargo.toml b/imag-tag/Cargo.toml index 4028ec62..33a36544 100644 --- a/imag-tag/Cargo.toml +++ b/imag-tag/Cargo.toml @@ -22,3 +22,6 @@ path = "../libimagerror" [dependencies.libimagentrytag] path = "../libimagentrytag" +[dependencies.libimagutil] +path = "../libimagutil" + diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index f7c91dd0..92d3b7f3 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -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); From 0635bffd789b95fa9ae8b363be65e25329893191 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 19:34:12 +0200 Subject: [PATCH 5/5] imag-store: Use util fn warn_exit() --- imag-store/src/delete.rs | 11 +++-------- imag-store/src/verify.rs | 6 ++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 537b638d..70594e2a 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -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)); } diff --git a/imag-store/src/verify.rs b/imag-store/src/verify.rs index ca836e3f..b22d5909 100644 --- a/imag-store/src/verify.rs +++ b/imag-store/src/verify.rs @@ -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); } }