From 41e981fa48347eae4395861fab11e47d98031983 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 22 Apr 2019 12:44:24 +0200 Subject: [PATCH] Add force-override option to "imag-contact import" This patch adds the option to force-override the ref data in the imported entries. This is necessary when importing contact data which is already in the store, but where the reference data has changed (for example if the hash of the file has changed, this might come in handy at some point). Signed-off-by: Matthias Beyer --- bin/domain/imag-contact/src/main.rs | 9 +++++---- bin/domain/imag-contact/src/ui.rs | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/domain/imag-contact/src/main.rs b/bin/domain/imag-contact/src/main.rs index 821d271f..bc950fa1 100644 --- a/bin/domain/imag-contact/src/main.rs +++ b/bin/domain/imag-contact/src/main.rs @@ -157,8 +157,9 @@ fn list(rt: &Runtime) { } 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 scmd = rt.cli().subcommand_matches("import").unwrap(); // secured by main + let force_override = scmd.is_present("force-override"); + 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() @@ -180,7 +181,7 @@ fn import(rt: &Runtime) { if path.is_file() { let entry = rt .store() - .retrieve_from_path(&path, &ref_config, &collection_name) + .retrieve_from_path(&path, &ref_config, &collection_name, force_override) .map_err_trace_exit_unwrap(); let _ = rt.report_touched(entry.get_location()).unwrap_or_exit(); @@ -194,7 +195,7 @@ fn import(rt: &Runtime) { let pb = PathBuf::from(entry.path()); let fle = rt .store() - .retrieve_from_path(&pb, &ref_config, &collection_name) + .retrieve_from_path(&pb, &ref_config, &collection_name, force_override) .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 4a0b1095..c07a938d 100644 --- a/bin/domain/imag-contact/src/ui.rs +++ b/bin/domain/imag-contact/src/ui.rs @@ -65,6 +65,12 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .value_name("PATH") .help("Import from this file/directory")) + .arg(Arg::with_name("force-override") + .long("force") + .takes_value(false) + .required(false) + .multiple(false) + .help("Force to override existing entries")) ) .subcommand(SubCommand::with_name("show")