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>
This commit is contained in:
Matthias Beyer 2019-02-20 13:07:59 +01:00
parent a959167b15
commit dfc02a5679
6 changed files with 50 additions and 35 deletions

View file

@ -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"]

View file

@ -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))
}

View file

@ -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))
}

View file

@ -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"

View file

@ -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;

View file

@ -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))
}