From 072564f6b833df13f21479013c0484fff81ccc1e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 15 May 2016 00:03:51 +0200 Subject: [PATCH 1/2] Remove feature: setting tags --- imag-tag/src/main.rs | 13 ++----------- imag-tag/src/ui.rs | 8 -------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 977098c0..278f3978 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -44,9 +44,8 @@ fn main() { || { let add = rt.cli().value_of("add"); let rem = rt.cli().value_of("remove"); - let set = rt.cli().value_of("set"); - alter(&rt, id, add, rem, set); + alter(&rt, id, add, rem); }, |name| { debug!("Call: {}", name); @@ -60,7 +59,7 @@ fn main() { }); } -fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Option<&str>) { +fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>) { let path = { match build_entry_path(rt.store(), id) { Err(e) => { @@ -93,14 +92,6 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti } } }); - - set.map(|tags| { - info!("Setting tags '{}'", tags); - let tags : Vec<_> = tags.split(',').map(String::from).collect(); - if let Err(e) = e.set_tags(&tags) { - trace_error(&e); - } - }); }) .map_err(|e| { info!("No entry."); diff --git a/imag-tag/src/ui.rs b/imag-tag/src/ui.rs index 4f78bf1f..74916879 100644 --- a/imag-tag/src/ui.rs +++ b/imag-tag/src/ui.rs @@ -24,14 +24,6 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .multiple(true) .help("Remove this tag")) - .arg(Arg::with_name("set") - .long("set") - .short("s") - .takes_value(true) - .required(false) - .multiple(true) - .help("Set these tags")) - .subcommand(SubCommand::with_name("list") .about("List tags (default)") .version("0.1") From 332dba028cbbe76fb06751890bab30cc2ff868dc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 15 May 2016 00:04:13 +0200 Subject: [PATCH 2/2] Rewrite adding/removing to allow adding and removing multiple tags --- imag-tag/src/main.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 278f3978..f070dbd1 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -42,8 +42,8 @@ fn main() { .subcommand_name() .map_or_else( || { - let add = rt.cli().value_of("add"); - let rem = rt.cli().value_of("remove"); + let add = rt.cli().values_of("add").map(|o| o.map(String::from)); + let rem = rt.cli().values_of("remove").map(|o| o.map(String::from)); alter(&rt, id, add, rem); }, @@ -59,7 +59,7 @@ fn main() { }); } -fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>) { +fn alter>(rt: &Runtime, id: &str, add: Option, rem: Option) { let path = { match build_entry_path(rt.store(), id) { Err(e) => { @@ -76,22 +76,22 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>) { .retrieve(path) .map(|mut e| { add.map(|tags| { - for tag in tags.split(',') { - info!("Adding tag '{}'", tag); - if let Err(e) = e.add_tag(String::from(tag)) { + for tag in tags { + debug!("Adding tag '{:?}'", tag); + if let Err(e) = e.add_tag(tag) { trace_error(&e); } } - }); + }); // it is okay to ignore a None here rem.map(|tags| { - for tag in tags.split(',') { - info!("Removing tag '{}'", tag); - if let Err(e) = e.remove_tag(String::from(tag)) { + for tag in tags { + debug!("Removing tag '{:?}'", tag); + if let Err(e) = e.remove_tag(tag) { trace_error(&e); } } - }); + }); // it is okay to ignore a None here }) .map_err(|e| { info!("No entry.");