Merge pull request #404 from matthiasbeyer/imag-tag/add-remove-multiple

Imag tag/add remove multiple
This commit is contained in:
Matthias Beyer 2016-05-17 00:20:16 +02:00
commit 629dfccb71
2 changed files with 12 additions and 29 deletions

View file

@ -42,11 +42,10 @@ fn main() {
.subcommand_name() .subcommand_name()
.map_or_else( .map_or_else(
|| { || {
let add = rt.cli().value_of("add"); let add = rt.cli().values_of("add").map(|o| o.map(String::from));
let rem = rt.cli().value_of("remove"); let rem = rt.cli().values_of("remove").map(|o| o.map(String::from));
let set = rt.cli().value_of("set");
alter(&rt, id, add, rem, set); alter(&rt, id, add, rem);
}, },
|name| { |name| {
debug!("Call: {}", 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<SI: Iterator<Item = String>>(rt: &Runtime, id: &str, add: Option<SI>, rem: Option<SI>) {
let path = { let path = {
match build_entry_path(rt.store(), id) { match build_entry_path(rt.store(), id) {
Err(e) => { Err(e) => {
@ -77,30 +76,22 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
.retrieve(path) .retrieve(path)
.map(|mut e| { .map(|mut e| {
add.map(|tags| { add.map(|tags| {
for tag in tags.split(',') { for tag in tags {
info!("Adding tag '{}'", tag); debug!("Adding tag '{:?}'", tag);
if let Err(e) = e.add_tag(String::from(tag)) { if let Err(e) = e.add_tag(tag) {
trace_error(&e); trace_error(&e);
} }
} }
}); }); // it is okay to ignore a None here
rem.map(|tags| { rem.map(|tags| {
for tag in tags.split(',') { for tag in tags {
info!("Removing tag '{}'", tag); debug!("Removing tag '{:?}'", tag);
if let Err(e) = e.remove_tag(String::from(tag)) { if let Err(e) = e.remove_tag(tag) {
trace_error(&e); trace_error(&e);
} }
} }
}); }); // it is okay to ignore a None here
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| { .map_err(|e| {
info!("No entry."); info!("No entry.");

View file

@ -24,14 +24,6 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.multiple(true) .multiple(true)
.help("Remove this tag")) .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") .subcommand(SubCommand::with_name("list")
.about("List tags (default)") .about("List tags (default)")
.version("0.1") .version("0.1")