summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-04-16 18:33:02 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-04-22 14:26:56 +0200
commit9b7edfc6c1299fad78376de8feb39a52b9e3210f (patch)
tree8301719133f7915d7376d93080b3f14d1d2bfdba /bin
parent1c851bbb797ec30b344fc3a86a5dd30d431ab9ed (diff)
Rewrite imag-contact to handle reference storing
This patch rewrites the imag-contact binary to be able to work with the new libimagcontact interface, which now uses libimagentryref for storing references to the actual vcard files. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'bin')
-rw-r--r--bin/domain/imag-contact/Cargo.toml7
-rw-r--r--bin/domain/imag-contact/src/create.rs20
-rw-r--r--bin/domain/imag-contact/src/main.rs20
-rw-r--r--bin/domain/imag-contact/src/ui.rs9
4 files changed, 49 insertions, 7 deletions
diff --git a/bin/domain/imag-contact/Cargo.toml b/bin/domain/imag-contact/Cargo.toml
index 53b4fb81..acaeb1bc 100644
--- a/bin/domain/imag-contact/Cargo.toml
+++ b/bin/domain/imag-contact/Cargo.toml
@@ -24,7 +24,6 @@ maintenance = { status = "actively-developed" }
[dependencies]
log = "0.4.0"
toml = "0.4"
-toml-query = "0.8"
vobject = "0.7"
handlebars = "1.0"
walkdir = "2"
@@ -46,3 +45,9 @@ version = "^2.29"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[dependencies.toml-query]
+#version = "0.8"
+default-features = false
+features = ["typed"]
+git = "https://github.com/matthiasbeyer/toml-query"
+branch = "master"
diff --git a/bin/domain/imag-contact/src/create.rs b/bin/domain/imag-contact/src/create.rs
index 622a2ccb..4144279e 100644
--- a/bin/domain/imag-contact/src/create.rs
+++ b/bin/domain/imag-contact/src/create.rs
@@ -43,9 +43,11 @@ use vobject::vcard::Vcard;
use vobject::vcard::VcardBuilder;
use vobject::write_component;
use toml_query::read::TomlValueReadExt;
+use toml_query::read::Partial;
use toml::Value;
use uuid::Uuid;
use failure::Error;
+use failure::err_msg;
use libimagcontact::store::ContactStore;
use libimagrt::runtime::Runtime;
@@ -80,8 +82,20 @@ fn ask_continue(inputstream: &mut Read, outputstream: &mut Write) -> bool {
}
pub fn create(rt: &Runtime) {
- let scmd = rt.cli().subcommand_matches("create").unwrap();
- let mut template = String::from(TEMPLATE);
+ let scmd = rt.cli().subcommand_matches("create").unwrap();
+ let mut template = String::from(TEMPLATE);
+ let collection_name = rt.cli().value_of("ref-collection-name").unwrap_or("contacts");
+ let collection_name = String::from(collection_name);
+ let ref_config = rt // TODO: Re-Deserialize to libimagentryref::reference::Config
+ .config()
+ .ok_or_else(|| err_msg("Configuration missing, cannot continue!"))
+ .map_err_trace_exit_unwrap()
+ .read_partial::<libimagentryref::reference::Config>()
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap()
+ .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))
+ .map_err_trace_exit_unwrap();
+ // TODO: Refactor the above to libimagutil or libimagrt?
let (mut dest, location, uuid) : (Box<Write>, Option<PathBuf>, String) = {
if let Some(mut fl) = scmd.value_of("file-location").map(PathBuf::from) {
@@ -202,7 +216,7 @@ pub fn create(rt: &Runtime) {
if let Some(location) = location {
if !scmd.is_present("dont-track") {
let entry = rt.store()
- .create_from_path(&location)
+ .create_from_path(&location, &ref_config, &collection_name)
.map_err_trace_exit_unwrap();
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs
index 39c68ddf..821d271f 100644
--- a/bin/domain/imag-contact/src/main.rs
+++ b/bin/domain/imag-contact/src/main.rs
@@ -43,7 +43,7 @@ extern crate handlebars;
extern crate walkdir;
extern crate uuid;
extern crate serde_json;
-extern crate failure;
+#[macro_use] extern crate failure;
extern crate libimagcontact;
extern crate libimagstore;
@@ -59,7 +59,9 @@ use std::io::Write;
use handlebars::Handlebars;
use clap::ArgMatches;
+use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
+use toml_query::read::Partial;
use walkdir::WalkDir;
use failure::Error;
use failure::err_msg;
@@ -158,6 +160,18 @@ fn import(rt: &Runtime) {
let scmd = rt.cli().subcommand_matches("import").unwrap(); // secured by main
let path = scmd.value_of("path").map(PathBuf::from).unwrap(); // secured by clap
+ let collection_name = rt.cli().value_of("contact-ref-collection-name").unwrap(); // default by clap
+ let ref_config = rt.config()
+ .ok_or_else(|| format_err!("No configuration, cannot continue!"))
+ .map_err_trace_exit_unwrap()
+ .read_partial::<libimagentryref::reference::Config>()
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap()
+ .ok_or_else(|| format_err!("Configuration missing: {}", libimagentryref::reference::Config::LOCATION))
+ .map_err_trace_exit_unwrap();
+ // TODO: Refactor the above to libimagutil or libimagrt?
+
+
if !path.exists() {
error!("Path does not exist");
exit(1)
@@ -166,7 +180,7 @@ fn import(rt: &Runtime) {
if path.is_file() {
let entry = rt
.store()
- .retrieve_from_path(&path)
+ .retrieve_from_path(&path, &ref_config, &collection_name)
.map_err_trace_exit_unwrap();
let _ = rt.report_touched(entry.get_location()).unwrap_or_exit();
@@ -180,7 +194,7 @@ fn import(rt: &Runtime) {
let pb = PathBuf::from(entry.path());
let fle = rt
.store()
- .retrieve_from_path(&pb)
+ .retrieve_from_path(&pb, &ref_config, &collection_name)
.map_err_trace_exit_unwrap();
let _ = rt.report_touched(fle.get_location()).unwrap_or_exit();
diff --git a/bin/domain/imag-contact/src/ui.rs b/bin/domain/imag-contact/src/ui.rs
index 5b939422..4a0b1095 100644
--- a/bin/domain/imag-contact/src/ui.rs
+++ b/bin/domain/imag-contact/src/ui.rs
@@ -21,6 +21,14 @@ use clap::{Arg, App, SubCommand};
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
+ .arg(Arg::with_name("contact-ref-collection-name")
+ .long("ref-collection")
+ .takes_value(true)
+ .required(false)
+ .multiple(false)
+ .default_value("contacts")
+ .help("Name (Key) of the basepath setting in the configuration file to use"))
+
.subcommand(SubCommand::with_name("list")
.about("List contacts")
.version("0.1")
@@ -56,6 +64,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.multiple(false)
.value_name("PATH")
.help("Import from this file/directory"))
+
)
.subcommand(SubCommand::with_name("show")