summaryrefslogtreecommitdiffstats
path: root/bin/core/imag-link/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/core/imag-link/src/lib.rs')
-rw-r--r--bin/core/imag-link/src/lib.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/bin/core/imag-link/src/lib.rs b/bin/core/imag-link/src/lib.rs
index 31ec46c5..d4054429 100644
--- a/bin/core/imag-link/src/lib.rs
+++ b/bin/core/imag-link/src/lib.rs
@@ -37,7 +37,7 @@
#[macro_use] extern crate log;
extern crate clap;
extern crate url;
-#[macro_use] extern crate failure;
+#[macro_use] extern crate anyhow;
#[macro_use] extern crate prettytable;
#[cfg(test)] extern crate toml;
#[cfg(test)] extern crate toml_query;
@@ -60,7 +60,7 @@ use std::io::Write;
use std::path::PathBuf;
-use failure::err_msg;
+
use libimagentryurl::linker::UrlLinker;
use libimagentrylink::linkable::Linkable;
@@ -71,7 +71,7 @@ use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
use url::Url;
-use failure::Fallible as Result;
+use anyhow::Result;
use clap::App;
mod ui;
@@ -98,14 +98,14 @@ impl ImagApplication for ImagLink {
if rt.handle_unknown_subcommand("imag-link", other, rt.cli())?.success() {
Ok(())
} else {
- Err(format_err!("Subcommand failed"))
+ Err(anyhow!("Subcommand failed"))
}
},
}
} else if let (Some(from), Some(to)) = (rt.cli().value_of("from"), rt.cli().values_of("to")) {
link_from_to(&rt, from, to)
} else {
- Err(err_msg("No commandline call"))
+ Err(anyhow!("No commandline call"))
}
}
@@ -138,13 +138,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
where I: Iterator<Item = &'a str>
{
let directional = rt.cli().is_present("directional");
- let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| err_msg("No 'from' entry"))?;
+ let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| anyhow!("No 'from' entry"))?;
for entry in to {
debug!("Handling 'to' entry: {:?}", entry);
if rt.store().get(PathBuf::from(entry))?.is_none() {
debug!("Linking externally: {:?} -> {:?}", from, entry);
- let url = Url::parse(entry).map_err(|e| format_err!("Error parsing URL: {:?}", e))?;
+ let url = Url::parse(entry).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?;
let iter = from_entry
.add_url(rt.store(), url)?
@@ -158,13 +158,13 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
let entr_id = StoreId::new(PathBuf::from(entry))?;
if from_id == entr_id {
- return Err(err_msg("Cannot link entry with itself. Exiting"))
+ return Err(anyhow!("Cannot link entry with itself. Exiting"))
}
let mut to_entry = rt
.store()
.get(entr_id)?
- .ok_or_else(|| format_err!("No 'to' entry: {}", entry))?;
+ .ok_or_else(|| anyhow!("No 'to' entry: {}", entry))?;
if directional {
from_entry.add_link_to(&mut to_entry)?;
@@ -188,11 +188,11 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
.value_of("from")
.map(PathBuf::from)
.and_then(|id| rt.store().get(id).transpose())
- .ok_or_else(|| err_msg("No 'from' entry"))??;
+ .ok_or_else(|| anyhow!("No 'from' entry"))??;
rt
.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(|id| match rt.store().get(id.clone())? {
Some(mut to_entry) => {
@@ -204,13 +204,13 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
// looks like this is not an entry, but a filesystem URI and therefor an
// external link...?
if id.local().is_file() {
- let pb = id.local().to_str().ok_or_else(|| format_err!("Not StoreId and not a Path: {}", id))?;
- let url = Url::parse(pb).map_err(|e| format_err!("Error parsing URL: {:?}", e))?;
+ let pb = id.local().to_str().ok_or_else(|| anyhow!("Not StoreId and not a Path: {}", id))?;
+ let url = Url::parse(pb).map_err(|e| anyhow!("Error parsing URL: {:?}", e))?;
from.remove_url(rt.store(), url)?;
info!("Ok: {}", id);
Ok(())
} else {
- Err(format_err!("Entry not found: {:?}", id))
+ Err(anyhow!("Entry not found: {:?}", id))
}
}
})
@@ -222,12 +222,12 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
fn unlink(rt: &Runtime) -> Result<()> {
rt
.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(|id| {
rt.store()
.get(id.clone())?
- .ok_or_else(|| format_err!("No entry for {}", id))?
+ .ok_or_else(|| anyhow!("No entry for {}", id))?
.unlink(rt.store())?;
rt.report_touched(&id)
@@ -247,10 +247,10 @@ fn list_linkings(rt: &Runtime) -> Result<()> {
tab.set_titles(row!["#", "Link"]);
rt.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
+ .ok_or_else(|| anyhow!("No ids supplied"))?
.into_iter()
.map(|id| {
- let entry = rt.store().get(id.clone())?.ok_or_else(|| format_err!("Not found: {}", id))?;
+ let entry = rt.store().get(id.clone())?.ok_or_else(|| anyhow!("Not found: {}", id))?;
for (i, link) in entry.links()?.enumerate() {
let link = link.to_str()?;
@@ -302,8 +302,8 @@ mod tests {
use toml::value::Value;
use toml_query::read::TomlValueReadExt;
- use failure::Fallible as Result;
- use failure::Error;
+ use anyhow::Result;
+ use anyhow::Error;
use libimagrt::runtime::Runtime;
use libimagstore::storeid::StoreId;