Add BM::command_add_tags()
This commit is contained in:
parent
cbefa577e9
commit
46b7ae9384
2 changed files with 78 additions and 0 deletions
31
etc/cli.yml
31
etc/cli.yml
|
@ -118,6 +118,37 @@ subcommands:
|
|||
required: false
|
||||
takes_value: true
|
||||
|
||||
- add_tags:
|
||||
about: Add tags to bookmark(s)
|
||||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- with_id:
|
||||
long: with-id
|
||||
help: Add tags to bookmark with ID
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- with_match:
|
||||
short: m
|
||||
long: with-match
|
||||
help: Add tags to bookmark(s) which match this regex
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- with_tags:
|
||||
long: with-tags
|
||||
help: Add tags to bookmark(s) which have these tag(s)
|
||||
required: false
|
||||
takes_value: true
|
||||
|
||||
- tags:
|
||||
short: t
|
||||
long: tags
|
||||
help: Add these tags
|
||||
required: true
|
||||
takes_value: true
|
||||
|
||||
- todo:
|
||||
about: Todo module
|
||||
version: 0.1
|
||||
|
|
|
@ -152,6 +152,49 @@ impl<'a> BM<'a> {
|
|||
return result;
|
||||
}
|
||||
|
||||
fn command_add_tags(&self, matches: &ArgMatches) -> bool {
|
||||
use self::header::set_tags_in_header;
|
||||
|
||||
let tags = matches.value_of("tags")
|
||||
.map(|ts| {
|
||||
ts.split(",")
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>()
|
||||
})
|
||||
.unwrap_or(vec![]);
|
||||
let (filter, files) = self.get_files(matches, "with_id", "with_match", "with_tags");
|
||||
|
||||
if tags.len() == 0 {
|
||||
error!("No tags to add, exiting.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if !filter {
|
||||
warn!("There were no filter applied when loading the files");
|
||||
}
|
||||
|
||||
let result = files
|
||||
.iter()
|
||||
.map(|file| {
|
||||
debug!("Adding tags to file: {:?}", file);
|
||||
let f = file.deref().borrow();
|
||||
let hdr = f.header();
|
||||
let mut ts = get_tags_from_header(hdr);
|
||||
let mut append_tags = tags.clone();
|
||||
ts.append(&mut append_tags);
|
||||
set_tags_in_header(hdr, ts);
|
||||
true
|
||||
})
|
||||
.all(|x| x);
|
||||
|
||||
if result {
|
||||
info!("Adding tags to links succeeded");
|
||||
} else {
|
||||
error!("Adding tags to links failed");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
fn get_files(&self,
|
||||
matches: &ArgMatches,
|
||||
|
@ -248,6 +291,10 @@ impl<'a> Module<'a> for BM<'a> {
|
|||
self.command_remove(matches.subcommand_matches("remove").unwrap())
|
||||
},
|
||||
|
||||
Some("add_tags") => {
|
||||
self.command_add_tags(matches.subcommand_matches("add_tags").unwrap())
|
||||
},
|
||||
|
||||
Some(_) | None => {
|
||||
info!("No command given, doing nothing");
|
||||
false
|
||||
|
|
Loading…
Reference in a new issue