summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-bookmark/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-bookmark/src/lib.rs')
-rw-r--r--bin/domain/imag-bookmark/src/lib.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/domain/imag-bookmark/src/lib.rs b/bin/domain/imag-bookmark/src/lib.rs
index 98f50fca..6782ed59 100644
--- a/bin/domain/imag-bookmark/src/lib.rs
+++ b/bin/domain/imag-bookmark/src/lib.rs
@@ -81,6 +81,7 @@ impl ImagApplication for ImagBookmark {
"add" => add(&rt),
"list" => list(&rt),
"remove" => remove(&rt),
+ "find" => find(&rt),
other => {
debug!("Unknown command");
if rt.handle_unknown_subcommand("imag-bookmark", other, rt.cli())?.success() {
@@ -160,3 +161,35 @@ fn remove(rt: &Runtime) -> Result<()> {
.collect()
}
+fn find(rt: &Runtime) -> Result<()> {
+ let substr = rt.cli().subcommand_matches("find").unwrap().value_of("substr").unwrap();
+
+ if let Some(ids) = rt.ids::<crate::ui::PathProvider>()? {
+ ids.into_iter()
+ .map(Ok)
+ .into_get_iter(rt.store())
+ } else {
+ rt.store()
+ .all_bookmarks()?
+ .into_get_iter()
+ }
+ .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
+ .and_then_ok(|fle| {
+ if fle.is_bookmark()? {
+ let url = fle
+ .get_url()?
+ .ok_or_else(|| format_err!("Failed to retrieve URL for {}", fle.get_location()))?;
+ if url.as_str().contains(substr) {
+ if !rt.output_is_pipe() {
+ writeln!(rt.stdout(), "{}", url)?;
+ }
+ rt.report_touched(fle.get_location()).map_err(Error::from)
+ } else {
+ Ok(())
+ }
+ } else {
+ Ok(())
+ }
+ })
+ .collect()
+}