Add BM::command_rm_tags()

This commit is contained in:
Matthias Beyer 2015-12-28 20:47:47 +01:00
parent 7e401b5881
commit bcbd568311
2 changed files with 44 additions and 0 deletions

View file

@ -149,6 +149,37 @@ subcommands:
required: true required: true
takes_value: true takes_value: true
- rm_tags:
about: Remove tags from bookmark(s)
version: 0.1
author: Matthias Beyer <mail@beyermatthias.de>
args:
- with_id:
long: with-id
help: Remove tags from bookmark with ID
required: false
takes_value: true
- with_match:
short: m
long: with-match
help: Remove tags from bookmark(s) which match this regex
required: false
takes_value: true
- with_tags:
long: with-tags
help: Remove tags from bookmark(s) which have these tag(s)
required: false
takes_value: true
- tags:
short: t
long: tags
help: Remove these tags
required: true
takes_value: true
- todo: - todo:
about: Todo module about: Todo module
version: 0.1 version: 0.1

View file

@ -160,6 +160,15 @@ impl<'a> BM<'a> {
}) })
} }
fn command_rm_tags(&self, matches: &ArgMatches) -> bool {
self.alter_tags_in_files(matches, |old_tags, cli_tags| {
old_tags.clone()
.into_iter()
.filter(|tag| !cli_tags.contains(tag))
.collect()
})
}
fn alter_tags_in_files<F>(&self, matches: &ArgMatches, generate_new_tags: F) -> bool fn alter_tags_in_files<F>(&self, matches: &ArgMatches, generate_new_tags: F) -> bool
where F: Fn(Vec<String>, &Vec<String>) -> Vec<String> where F: Fn(Vec<String>, &Vec<String>) -> Vec<String>
{ {
@ -313,6 +322,10 @@ impl<'a> Module<'a> for BM<'a> {
self.command_add_tags(matches.subcommand_matches("add_tags").unwrap()) self.command_add_tags(matches.subcommand_matches("add_tags").unwrap())
}, },
Some("rm_tags") => {
self.command_rm_tags(matches.subcommand_matches("rm_tags").unwrap())
},
Some(_) | None => { Some(_) | None => {
info!("No command given, doing nothing"); info!("No command given, doing nothing");
false false