summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-20 13:07:59 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-20 16:22:52 +0100
commitdfc02a56799504e268b02c089d9070ec1d038f9b (patch)
treeeeda58359f7a28d58bc626aeaf059672180f76bc
parenta959167b15d7ecfeb552253033f33cf0ece13e30 (diff)
downloadimag-dfc02a56799504e268b02c089d9070ec1d038f9b.zip
imag-dfc02a56799504e268b02c089d9070ec1d038f9b.tar.gz
Move helper function to libimagentref::util
This moves the helper function for getting the `Config` object from the configuration file via the runtime. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/core/imag-ref/Cargo.toml5
-rw-r--r--bin/core/imag-ref/src/main.rs19
-rw-r--r--bin/domain/imag-mail/src/main.rs15
-rw-r--r--lib/entry/libimagentryref/Cargo.toml7
-rw-r--r--lib/entry/libimagentryref/src/lib.rs2
-rw-r--r--lib/entry/libimagentryref/src/util.rs37
6 files changed, 50 insertions, 35 deletions
diff --git a/bin/core/imag-ref/Cargo.toml b/bin/core/imag-ref/Cargo.toml
index bf3cb6c..0c4b598 100644
--- a/bin/core/imag-ref/Cargo.toml
+++ b/bin/core/imag-ref/Cargo.toml
@@ -37,8 +37,3 @@ version = "^2.29"
default-features = false
features = ["color", "suggestions", "wrap_help"]
-[dependencies.toml-query]
-version = "0.8"
-default-features = false
-features = ["typed"]
-
diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs
index 63edf36..a9500be 100644
--- a/bin/core/imag-ref/src/main.rs
+++ b/bin/core/imag-ref/src/main.rs
@@ -35,9 +35,7 @@
)]
#[macro_use] extern crate log;
-#[macro_use] extern crate failure;
extern crate clap;
-extern crate toml_query;
extern crate libimagstore;
#[macro_use] extern crate libimagrt;
@@ -52,8 +50,6 @@ use ui::build_ui;
use std::process::exit;
use std::io::Write;
-use failure::Fallible as Result;
-
use libimagerror::trace::MapErrTrace;
use libimagerror::exit::ExitUnwrap;
use libimagrt::setup::generate_runtime_setup;
@@ -62,7 +58,7 @@ use libimagentryref::reference::Ref;
use libimagentryref::reference::MutRef;
use libimagentryref::reference::RefFassade;
use libimagentryref::hasher::default::DefaultHasher;
-use libimagentryref::reference::Config as RefConfig;
+use libimagentryref::util::get_ref_config;
fn main() {
let version = make_imag_version!();
@@ -92,7 +88,7 @@ fn main() {
fn deref(rt: &Runtime) {
let cmd = rt.cli().subcommand_matches("deref").unwrap();
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap();
- let cfg = get_ref_config(&rt).map_err_trace_exit_unwrap();
+ let cfg = get_ref_config(&rt, "imag-ref").map_err_trace_exit_unwrap();
let out = rt.stdout();
let mut outlock = out.lock();
@@ -163,14 +159,3 @@ fn create(rt: &Runtime) {
unimplemented!()
}
-fn get_ref_config(rt: &Runtime) -> Result<RefConfig> {
- use toml_query::read::TomlValueReadExt;
-
- let setting_name = "ref.basepathes";
-
- rt.config()
- .ok_or_else(|| format_err!("No configuration, cannot find collection name for ref collection"))?
- .read_deserialized::<RefConfig>(setting_name)?
- .ok_or_else(|| format_err!("Setting missing: {}", setting_name))
-}
-
diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs
index 59d7f64..8f7418d 100644
--- a/bin/domain/imag-mail/src/main.rs
+++ b/bin/domain/imag-mail/src/main.rs
@@ -51,7 +51,6 @@ use std::io::Write;
use std::path::PathBuf;
use failure::Fallible as Result;
-use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use libimagerror::trace::{MapErrTrace, trace_error};
@@ -62,6 +61,7 @@ use libimagmail::mail::Mail;
use libimagmail::store::MailStore;
use libimagmail::util;
use libimagentryref::reference::{Ref, RefFassade};
+use libimagentryref::util::get_ref_config;
use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagutil::info_result::*;
@@ -101,7 +101,7 @@ fn main() {
fn import_mail(rt: &Runtime) {
let collection_name = get_ref_collection_name(rt).map_err_trace_exit_unwrap();
- let refconfig = get_ref_config(rt).map_err_trace_exit_unwrap();
+ let refconfig = get_ref_config(rt, "imag-mail").map_err_trace_exit_unwrap();
let scmd = rt.cli().subcommand_matches("import-mail").unwrap();
let store = rt.store();
@@ -126,7 +126,7 @@ fn import_mail(rt: &Runtime) {
}
fn list(rt: &Runtime) {
- let refconfig = get_ref_config(rt).map_err_trace_exit_unwrap();
+ let refconfig = get_ref_config(rt, "imag-mail").map_err_trace_exit_unwrap();
let scmd = rt.cli().subcommand_matches("list").unwrap(); // safe via clap
let print_content = scmd.is_present("list-read");
@@ -251,12 +251,3 @@ fn get_ref_collection_name(rt: &Runtime) -> Result<String> {
.ok_or_else(|| format_err!("Setting missing: {}", setting_name))
}
-fn get_ref_config(rt: &Runtime) -> Result<::libimagentryref::reference::Config> {
- let setting_name = "ref.basepathes";
-
- rt.config()
- .ok_or_else(|| format_err!("No configuration, cannot find collection name for mail collection"))?
- .read_deserialized::<::libimagentryref::reference::Config>(setting_name)?
- .ok_or_else(|| format_err!("Setting missing: {}", setting_name))
-}
-
diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml
index 60692ac..ccec9af 100644
--- a/lib/entry/libimagentryref/Cargo.toml
+++ b/lib/entry/libimagentryref/Cargo.toml
@@ -25,14 +25,19 @@ log = "0.4.0"
failure = "0.1"
sha-1 = "0.8"
toml = "0.4"
-toml-query = "0.8"
serde = "1"
serde_derive = "1"
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
+libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
libimagentryutil = { version = "0.10.0", path = "../../../lib/entry/libimagentryutil" }
+[dependencies.toml-query]
+version = "0.8"
+default-features = false
+features = ["typed"]
+
[dev-dependencies]
env_logger = "0.5"
diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs
index 4d8e02e..95c40b2 100644
--- a/lib/entry/libimagentryref/src/lib.rs
+++ b/lib/entry/libimagentryref/src/lib.rs
@@ -45,6 +45,7 @@ extern crate toml_query;
extern crate sha1;
extern crate libimagstore;
+extern crate libimagrt;
extern crate libimagerror;
#[macro_use] extern crate libimagentryutil;
#[macro_use] extern crate failure;
@@ -54,4 +55,5 @@ extern crate env_logger;
pub mod hasher;
pub mod reference;
+pub mod util;
diff --git a/lib/entry/libimagentryref/src/util.rs b/lib/entry/libimagentryref/src/util.rs
new file mode 100644
index 0000000..1daf2e7
--- /dev/null
+++ b/lib/entry/libimagentryref/src/util.rs
@@ -0,0 +1,37 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use failure::Fallible as Result;
+
+use libimagrt::runtime::Runtime;
+
+use reference::Config as RefConfig;
+
+pub fn get_ref_config(rt: &Runtime, app_name: &'static str) -> Result<RefConfig> {
+ use toml_query::read::TomlValueReadExt;
+
+ let setting_name = "ref.basepathes";
+
+ rt.config()
+ .ok_or_else(|| format_err!("No configuration, cannot find collection name for {}", app_name))?
+ .read_deserialized::<RefConfig>(setting_name)?
+ .ok_or_else(|| format_err!("Setting missing: {}", setting_name))
+}
+
+