libimagentryview: Move from error-chain to failure
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
9b48dc27cd
commit
ebe2a9a110
8 changed files with 17 additions and 83 deletions
|
@ -22,7 +22,7 @@ maintenance = { status = "actively-developed" }
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
error-chain = "0.12"
|
failure = "0.1"
|
||||||
textwrap = "0.10"
|
textwrap = "0.10"
|
||||||
|
|
||||||
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
@ -31,7 +31,6 @@ libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror"
|
||||||
libimagentryedit = { version = "0.9.0", path = "../../../lib/entry/libimagentryedit" }
|
libimagentryedit = { version = "0.9.0", path = "../../../lib/entry/libimagentryedit" }
|
||||||
|
|
||||||
mdcat = { version = "0.8", optional = true }
|
mdcat = { version = "0.8", optional = true }
|
||||||
failure = { version = "0.1", optional = true }
|
|
||||||
|
|
||||||
[dependencies.pulldown-cmark]
|
[dependencies.pulldown-cmark]
|
||||||
version = "^0.1"
|
version = "^0.1"
|
||||||
|
@ -47,5 +46,5 @@ features = ["parsing", "assets", "dump-load"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "markdownviewer" ]
|
default = [ "markdownviewer" ]
|
||||||
markdownviewer = ["mdcat", "failure", "pulldown-cmark", "syntect"]
|
markdownviewer = ["mdcat", "pulldown-cmark", "syntect"]
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,10 @@ use libimagrt::runtime::Runtime;
|
||||||
use libimagentryedit::edit::edit_in_tmpfile;
|
use libimagentryedit::edit::edit_in_tmpfile;
|
||||||
|
|
||||||
use viewer::Viewer;
|
use viewer::Viewer;
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
use error::ResultExt;
|
use failure::ResultExt;
|
||||||
use error::ViewErrorKind as VEK;
|
use failure::Error;
|
||||||
|
use failure::err_msg;
|
||||||
|
|
||||||
pub struct EditorView<'a>(&'a Runtime<'a>);
|
pub struct EditorView<'a>(&'a Runtime<'a>);
|
||||||
|
|
||||||
|
@ -41,7 +42,9 @@ impl<'a> Viewer for EditorView<'a> {
|
||||||
where W: Write
|
where W: Write
|
||||||
{
|
{
|
||||||
let mut entry = e.to_str()?.clone().to_string();
|
let mut entry = e.to_str()?.clone().to_string();
|
||||||
edit_in_tmpfile(self.0, &mut entry).chain_err(|| VEK::ViewError)
|
edit_in_tmpfile(self.0, &mut entry)
|
||||||
|
.context(err_msg("Error while viewing"))
|
||||||
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ use syntect::parsing::SyntaxSet;
|
||||||
use mdcat;
|
use mdcat;
|
||||||
|
|
||||||
use viewer::Viewer;
|
use viewer::Viewer;
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
pub struct MarkdownViewer<'a> {
|
pub struct MarkdownViewer<'a> {
|
||||||
rt: &'a Runtime<'a>,
|
rt: &'a Runtime<'a>,
|
||||||
|
@ -66,8 +67,7 @@ impl<'a> Viewer for MarkdownViewer<'a> {
|
||||||
base_dir,
|
base_dir,
|
||||||
self.resource_access.clone(),
|
self.resource_access.clone(),
|
||||||
syntax_set)
|
syntax_set)
|
||||||
.map_err(|e| e.compat())
|
.map_err(Error::from)
|
||||||
.map_err(::error::ViewError::from)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::io::Write;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use viewer::Viewer;
|
use viewer::Viewer;
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
pub struct PlainViewer {
|
pub struct PlainViewer {
|
||||||
show_header: bool
|
show_header: bool
|
||||||
|
|
|
@ -24,7 +24,7 @@ use libimagstore::store::Entry;
|
||||||
use toml::ser::to_string;
|
use toml::ser::to_string;
|
||||||
|
|
||||||
use viewer::Viewer;
|
use viewer::Viewer;
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
pub struct StdoutViewer {
|
pub struct StdoutViewer {
|
||||||
view_header: bool,
|
view_header: bool,
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
|
||||||
// License as published by the Free Software Foundation; version
|
|
||||||
// 2.1 of the License.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
|
||||||
// License along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
//
|
|
||||||
|
|
||||||
error_chain! {
|
|
||||||
types {
|
|
||||||
ViewError, ViewErrorKind, ResultExt, Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreign_links {
|
|
||||||
Failure(::failure::Compat<::failure::Error>) #[cfg(feature = "markdownviewer")];
|
|
||||||
IO(::std::io::Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
links {
|
|
||||||
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
|
|
||||||
}
|
|
||||||
|
|
||||||
errors {
|
|
||||||
Unknown {
|
|
||||||
description("Unknown view error")
|
|
||||||
display("Unknown view error")
|
|
||||||
}
|
|
||||||
|
|
||||||
GlobError {
|
|
||||||
description("Error while glob()ing")
|
|
||||||
display("Error while glob()ing")
|
|
||||||
}
|
|
||||||
|
|
||||||
PatternError {
|
|
||||||
description("Error in glob() pattern")
|
|
||||||
display("Error in glob() pattern")
|
|
||||||
}
|
|
||||||
|
|
||||||
PatternBuildingError {
|
|
||||||
description("Could not build glob() pattern")
|
|
||||||
display("Could not build glob() pattern")
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewError {
|
|
||||||
description("Failed to start viewer")
|
|
||||||
display("Failed to start viewer")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,15 +36,12 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
#[macro_use] extern crate error_chain;
|
|
||||||
extern crate textwrap;
|
extern crate textwrap;
|
||||||
|
extern crate failure;
|
||||||
|
|
||||||
#[cfg(feature = "markdownviewer")]
|
#[cfg(feature = "markdownviewer")]
|
||||||
extern crate mdcat;
|
extern crate mdcat;
|
||||||
|
|
||||||
#[cfg(feature = "markdownviewer")]
|
|
||||||
extern crate failure;
|
|
||||||
|
|
||||||
#[cfg(feature = "markdownviewer")]
|
#[cfg(feature = "markdownviewer")]
|
||||||
extern crate pulldown_cmark;
|
extern crate pulldown_cmark;
|
||||||
|
|
||||||
|
@ -56,7 +53,6 @@ extern crate libimagrt;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagentryedit;
|
extern crate libimagentryedit;
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
pub mod viewer;
|
pub mod viewer;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::ops::Deref;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
use error::Result;
|
use failure::Fallible as Result;
|
||||||
|
|
||||||
pub trait Viewer {
|
pub trait Viewer {
|
||||||
|
|
||||||
|
@ -35,9 +35,7 @@ pub trait Viewer {
|
||||||
W: Write
|
W: Write
|
||||||
{
|
{
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
if let Err(e) = self.view_entry(entry.deref(), sink) {
|
let _ = self.view_entry(entry.deref(), sink)?;
|
||||||
return Err(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue