summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-07-02 08:33:35 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-07-02 08:33:35 +0800
commitaf7a09c53faf9ebeeb8c0a15278b510738d1f34f (patch)
treeb111f49ee3ee6bed4044138e68662786635762dc /src
parent9ac025f7e546514581aaa96f96b8af476988d384 (diff)
Use 'anyhow' instead of 'failure' to simplify code and reduce bloat
Diffstat (limited to 'src')
-rw-r--r--src/aggregate.rs6
-rw-r--r--src/interactive/app/eventloop.rs16
-rw-r--r--src/interactive/app/handlers.rs4
-rw-r--r--src/interactive/app_test/journeys_readonly.rs12
-rw-r--r--src/interactive/app_test/journeys_with_writes.rs4
-rw-r--r--src/interactive/app_test/unit.rs6
-rw-r--r--src/interactive/app_test/utils.rs14
-rw-r--r--src/lib.rs1
-rw-r--r--src/main.rs11
-rw-r--r--src/traverse.rs6
10 files changed, 34 insertions, 46 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index fdc6694..d40a0cf 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -1,5 +1,5 @@
use crate::{crossdev, InodeFilter, WalkOptions, WalkResult};
-use failure::Error;
+use anyhow::Result;
use filesize::PathExt;
use std::borrow::Cow;
use std::{fmt, io, path::Path};
@@ -14,7 +14,7 @@ pub fn aggregate(
compute_total: bool,
sort_by_size_in_bytes: bool,
paths: impl IntoIterator<Item = impl AsRef<Path>>,
-) -> Result<(WalkResult, Statistics), Error> {
+) -> Result<(WalkResult, Statistics)> {
let mut res = WalkResult::default();
let mut stats = Statistics::default();
stats.smallest_file_in_bytes = u128::max_value();
@@ -125,7 +125,7 @@ fn write_path<C: fmt::Display>(
num_bytes: u128,
num_errors: u64,
path_color: C,
-) -> Result<(), io::Error> {
+) -> std::result::Result<(), io::Error> {
writeln!(
out,
"{byte_color}{:>byte_column_width$}{byte_color_reset} {path_color}{}{path_color_reset}{}",
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index b34c170..c815ed4 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -4,11 +4,11 @@ use crate::interactive::{
ByteVisualization, CursorDirection, CursorMode, DisplayOptions, EntryDataBundle, MarkEntryMode,
SortMode,
};
+use anyhow::Result;
use dua::{
traverse::{Traversal, TreeIndex},
WalkOptions, WalkResult,
};
-use failure::Error;
use std::{collections::BTreeMap, io, path::PathBuf};
use termion::{event::Key, input::TermRead};
use tui::backend::Backend;
@@ -51,7 +51,7 @@ impl AppState {
traversal: &Traversal,
display: DisplayOptions,
terminal: &mut Terminal<B>,
- ) -> Result<(), Error>
+ ) -> Result<()>
where
B: Backend,
{
@@ -69,8 +69,8 @@ impl AppState {
traversal: &mut Traversal,
display: &mut DisplayOptions,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = Result<Key, io::Error>>,
- ) -> Result<ProcessingResult, Error>
+ keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ ) -> Result<ProcessingResult>
where
B: Backend,
{
@@ -159,7 +159,7 @@ pub fn draw_window<B>(
window: &mut MainWindow,
props: MainWindowProps,
terminal: &mut Terminal<B>,
-) -> Result<(), Error>
+) -> Result<()>
where
B: Backend,
{
@@ -183,8 +183,8 @@ impl TerminalApp {
pub fn process_events<B>(
&mut self,
terminal: &mut Terminal<B>,
- keys: impl Iterator<Item = Result<Key, io::Error>>,
- ) -> Result<WalkResult, Error>
+ keys: impl Iterator<Item = std::result::Result<Key, io::Error>>,
+ ) -> Result<WalkResult>
where
B: Backend,
{
@@ -204,7 +204,7 @@ impl TerminalApp {
options: WalkOptions,
input: Vec<PathBuf>,
mode: Interaction,
- ) -> Result<Option<KeyboardInputAndApp>, Error>
+ ) -> Result<Option<KeyboardInputAndApp>>
where
B: Backend,
{
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs
index 44ebc3c..1758177 100644
--- a/src/interactive/app/handlers.rs
+++ b/src/interactive/app/handlers.rs
@@ -1,9 +1,7 @@
-use crate::interactive::widgets::MainWindow;
use crate::interactive::{
app::FocussedPane::*,
path_of, sorted_entries,
- widgets::MarkMode,
- widgets::{HelpPane, MarkPane},
+ widgets::{HelpPane, MainWindow, MarkMode, MarkPane},
AppState, DisplayOptions, EntryDataBundle,
};
use dua::traverse::{Traversal, TreeIndex};
diff --git a/src/interactive/app_test/journeys_readonly.rs b/src/interactive/app_test/journeys_readonly.rs
index 9461265..595491a 100644
--- a/src/interactive/app_test/journeys_readonly.rs
+++ b/src/interactive/app_test/journeys_readonly.rs
@@ -1,18 +1,18 @@
-use crate::{
- interactive::app_test::utils::{
+use crate::interactive::{
+ app_test::utils::{
fixture_str, index_by_name, initialized_app_and_terminal_from_fixture, node_by_index,
node_by_name,
},
- interactive::app_test::FIXTURE_PATH,
- interactive::SortMode,
+ app_test::FIXTURE_PATH,
+ SortMode,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
use std::ffi::OsString;
use termion::input::TermRead;
#[test]
-fn simple_user_journey_read_only() -> Result<(), Error> {
+fn simple_user_journey_read_only() -> Result<()> {
let long_root = "sample-02/dir";
let short_root = "sample-01";
let (mut terminal, mut app) =
diff --git a/src/interactive/app_test/journeys_with_writes.rs b/src/interactive/app_test/journeys_with_writes.rs
index cbd51cd..061fb4b 100644
--- a/src/interactive/app_test/journeys_with_writes.rs
+++ b/src/interactive/app_test/journeys_with_writes.rs
@@ -1,13 +1,13 @@
use crate::interactive::app_test::utils::{
initialized_app_and_terminal_from_paths, WritableFixture,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
use termion::event::Key;
use termion::input::TermRead;
#[test]
-fn basic_user_journey_with_deletion() -> Result<(), Error> {
+fn basic_user_journey_with_deletion() -> Result<()> {
let fixture = WritableFixture::from("sample-02");
let (mut terminal, mut app) = initialized_app_and_terminal_from_paths(&[fixture.root.clone()])?;
diff --git a/src/interactive/app_test/unit.rs b/src/interactive/app_test/unit.rs
index 71a90a9..e27d456 100644
--- a/src/interactive/app_test/unit.rs
+++ b/src/interactive/app_test/unit.rs
@@ -1,11 +1,11 @@
use crate::interactive::app_test::utils::{
debug, initialized_app_and_terminal_from_fixture, sample_01_tree, sample_02_tree,
};
-use failure::Error;
+use anyhow::Result;
use pretty_assertions::assert_eq;
#[test]
-fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(), Error> {
+fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<()> {
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-01"])?;
let expected_tree = sample_01_tree();
@@ -18,7 +18,7 @@ fn it_can_handle_ending_traversal_reaching_top_but_skipping_levels() -> Result<(
}
#[test]
-fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<(), Error> {
+fn it_can_handle_ending_traversal_without_reaching_the_top() -> Result<()> {
let (_, app) = initialized_app_and_terminal_from_fixture(&["sample-02"])?;
let expected_tree = sample_02_tree();
diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs
index ed94720..495ac01 100644
--- a/src/interactive/app_test/utils.rs
+++ b/src/interactive/app_test/utils.rs
@@ -1,12 +1,9 @@
-use crate::{
- interactive::app_test::FIXTURE_PATH,
- interactive::{Interaction, TerminalApp},
-};
+use crate::interactive::{app_test::FIXTURE_PATH, Interaction, TerminalApp};
+use anyhow::{Context, Error, Result};
use dua::{
traverse::{EntryData, Tree, TreeIndex},
ByteFormat, Color, TraversalSorting, WalkOptions,
};
-use failure::{Error, ResultExt};
use itertools::Itertools;
use jwalk::{DirEntry, WalkDir};
use petgraph::prelude::NodeIndex;
@@ -16,8 +13,7 @@ use std::{
fmt,
fs::{copy, create_dir_all, remove_dir, remove_file},
io::ErrorKind,
- path::Path,
- path::PathBuf,
+ path::{Path, PathBuf},
};
use tui::backend::TestBackend;
use tui_react::Terminal;
@@ -70,7 +66,7 @@ impl Drop for WritableFixture {
}
}
-fn delete_recursive(path: impl AsRef<Path>) -> Result<(), Error> {
+fn delete_recursive(path: impl AsRef<Path>) -> Result<()> {
let mut files: Vec<_> = Vec::new();
let mut dirs: Vec<_> = Vec::new();
@@ -95,7 +91,7 @@ fn delete_recursive(path: impl AsRef<Path>) -> Result<(), Error> {
.rev()
.map(|d| {
remove_dir(d)
- .with_context(|_| format!("Could not delete '{}'", d.display()))
+ .with_context(|| format!("Could not delete '{}'", d.display()))
.map_err(Error::from)
}),
)
diff --git a/src/lib.rs b/src/lib.rs
index 1e2a0c0..7988699 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,6 @@
#![cfg_attr(windows, feature(windows_by_handle))]
#![forbid(unsafe_code)]
-extern crate failure;
extern crate jwalk;
mod aggregate;
diff --git a/src/main.rs b/src/main.rs
index 3630be3..8104490 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,8 @@
#![forbid(unsafe_code)]
#![allow(clippy::match_bool)]
use crate::interactive::{Interaction, TerminalApp};
+use anyhow::{Context, Result};
use dua::{ByteFormat, Color, TraversalSorting};
-use failure::{Error, ResultExt};
-use failure_tools::ok_or_exit;
use std::{fs, io, io::Write, path::PathBuf, process};
use termion::{raw::IntoRawMode, screen::AlternateScreen};
use tui::backend::TermionBackend;
@@ -12,7 +11,7 @@ use tui_react::Terminal;
mod interactive;
mod options;
-fn run() -> Result<(), Error> {
+fn main() -> Result<()> {
use options::*;
let opt: options::Args = argh::from_env();
@@ -35,7 +34,7 @@ fn run() -> Result<(), Error> {
let mut terminal = {
let stdout = io::stdout()
.into_raw_mode()
- .with_context(|_| "Interactive mode requires a connected terminal")?;
+ .with_context(|| "Interactive mode requires a connected terminal")?;
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
Terminal::new(backend)?
@@ -129,7 +128,3 @@ fn cwd_dirlist() -> Result<Vec<PathBuf>, io::Error> {
v.sort();
Ok(v)
}
-
-fn main() {
- ok_or_exit(run())
-}
diff --git a/src/traverse.rs b/src/traverse.rs
index d19dd9e..0b56aa8 100644
--- a/src/traverse.rs
+++ b/src/traverse.rs
@@ -1,5 +1,5 @@
use crate::{crossdev, get_size_or_panic, InodeFilter, WalkOptions};
-use failure::Error;
+use anyhow::Result;
use filesize::PathExt;
use petgraph::{graph::NodeIndex, stable_graph::StableGraph, Directed, Direction};
use std::{path::PathBuf, time::Duration, time::Instant};
@@ -37,8 +37,8 @@ impl Traversal {
pub fn from_walk(
mut walk_options: WalkOptions,
input: Vec<PathBuf>,
- mut update: impl FnMut(&mut Traversal) -> Result<bool, Error>,
- ) -> Result<Option<Traversal>, Error> {
+ mut update: impl FnMut(&mut Traversal) -> Result<bool>,
+ ) -> Result<Option<Traversal>> {
fn set_size_or_panic(tree: &mut Tree, node_idx: TreeIndex, current_size_at_depth: u128) {
tree.node_weight_mut(node_idx)
.expect("node for parent index we just retrieved")