Add bm-open command
This commit is contained in:
parent
121bd0a8c5
commit
89101719ad
3 changed files with 72 additions and 0 deletions
25
etc/cli.yml
25
etc/cli.yml
|
@ -105,6 +105,31 @@ subcommands:
|
||||||
required: false
|
required: false
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
|
||||||
|
- open:
|
||||||
|
about: Open bookmarks
|
||||||
|
version: 0.1
|
||||||
|
author: Matthias Beyer <mail@beyermatthias.de>
|
||||||
|
args:
|
||||||
|
- id:
|
||||||
|
long: id
|
||||||
|
help: Open Bookmark with ID
|
||||||
|
required: false
|
||||||
|
takes_value: true
|
||||||
|
|
||||||
|
- match:
|
||||||
|
short: m
|
||||||
|
long: match
|
||||||
|
help: Open links matching regex
|
||||||
|
required: false
|
||||||
|
takes_value: true
|
||||||
|
|
||||||
|
- tags:
|
||||||
|
short: t
|
||||||
|
long: tags
|
||||||
|
help: Open links with these tags
|
||||||
|
required: false
|
||||||
|
takes_value: true
|
||||||
|
|
||||||
- remove:
|
- remove:
|
||||||
about: Remove bookmark(s)
|
about: Remove bookmark(s)
|
||||||
version: 0.1
|
version: 0.1
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#[macro_use] extern crate prettytable;
|
#[macro_use] extern crate prettytable;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate config;
|
extern crate config;
|
||||||
|
extern crate open;
|
||||||
|
|
||||||
pub use cli::CliConfig;
|
pub use cli::CliConfig;
|
||||||
pub use configuration::Configuration;
|
pub use configuration::Configuration;
|
||||||
|
|
|
@ -127,6 +127,48 @@ impl<'a> BM<'a> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subcommand: open
|
||||||
|
*/
|
||||||
|
fn command_open(&self, matches: &ArgMatches) -> bool {
|
||||||
|
use open;
|
||||||
|
|
||||||
|
let parser = Parser::new(JsonHeaderParser::new(None));
|
||||||
|
let filter : Box<CliFileFilter> = get_file_filter_by_cli(&parser, matches, "id", "match", "tags", None);
|
||||||
|
let result = self.rt
|
||||||
|
.store()
|
||||||
|
.load_for_module(self, &parser)
|
||||||
|
.iter()
|
||||||
|
.filter(|file| filter.filter_file(file))
|
||||||
|
.map(|file| {
|
||||||
|
debug!("File loaded, can open now: {:?}", file);
|
||||||
|
let f = file.deref().borrow();
|
||||||
|
get_url_from_header(f.header()).map(|url| {
|
||||||
|
if open::that(&url[..]).is_ok() {
|
||||||
|
info!("open({})", url);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
info!("could not open({})", url);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
.fold((0, 0), |acc, succeeded| {
|
||||||
|
let (worked, failed) = acc;
|
||||||
|
if succeeded {
|
||||||
|
(worked + 1, failed)
|
||||||
|
} else {
|
||||||
|
(worked, failed + 1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let (succ, fail) = result;
|
||||||
|
info!("open() succeeded for {} files", succ);
|
||||||
|
info!("open() failed for {} files", fail);
|
||||||
|
return fail == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subcommand: remove
|
* Subcommand: remove
|
||||||
*/
|
*/
|
||||||
|
@ -263,6 +305,10 @@ impl<'a> Module<'a> for BM<'a> {
|
||||||
self.command_list(matches.subcommand_matches("list").unwrap())
|
self.command_list(matches.subcommand_matches("list").unwrap())
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Some("open") => {
|
||||||
|
self.command_open(matches.subcommand_matches("open").unwrap())
|
||||||
|
},
|
||||||
|
|
||||||
Some("remove") => {
|
Some("remove") => {
|
||||||
self.command_remove(matches.subcommand_matches("remove").unwrap())
|
self.command_remove(matches.subcommand_matches("remove").unwrap())
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue