summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/cli.yml25
-rw-r--r--src/main.rs1
-rw-r--r--src/module/bm/mod.rs46
3 files changed, 72 insertions, 0 deletions
diff --git a/etc/cli.yml b/etc/cli.yml
index 33bd260b..21b38e0f 100644
--- a/etc/cli.yml
+++ b/etc/cli.yml
@@ -105,6 +105,31 @@ subcommands:
required: false
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:
about: Remove bookmark(s)
version: 0.1
diff --git a/src/main.rs b/src/main.rs
index 98e02ce2..504be825 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@
#[macro_use] extern crate prettytable;
extern crate url;
extern crate config;
+extern crate open;
pub use cli::CliConfig;
pub use configuration::Configuration;
diff --git a/src/module/bm/mod.rs b/src/module/bm/mod.rs
index 8ce411ff..fc6de35f 100644
--- a/src/module/bm/mod.rs
+++ b/src/module/bm/mod.rs
@@ -128,6 +128,48 @@ impl<'a> BM<'a> {
}
/**
+ * 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
*/
fn command_remove(&self, matches: &ArgMatches) -> bool {
@@ -263,6 +305,10 @@ impl<'a> Module<'a> for BM<'a> {
self.command_list(matches.subcommand_matches("list").unwrap())
},
+ Some("open") => {
+ self.command_open(matches.subcommand_matches("open").unwrap())
+ },
+
Some("remove") => {
self.command_remove(matches.subcommand_matches("remove").unwrap())
},