diff --git a/Cargo.lock b/Cargo.lock index 7666da6..e84efe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "garbage" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index a367be4..fe37378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "garbage" -version = "0.1.3" +version = "0.1.4" authors = ["Michael Zhang "] description = "cli tool for interacting with the freedesktop trashcan" license = "MIT" diff --git a/src/main.rs b/src/main.rs index d032551..e5491f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::fs; use std::io; use std::path::PathBuf; -use anyhow::Error; +use anyhow::Result; use structopt::StructOpt; use garbage::*; @@ -46,15 +46,12 @@ enum Command { Restore, } -fn main() -> Result<(), Error> { +fn run() -> Result<()> { env_logger::init(); let cmd = Command::from_args(); match cmd { - Command::Empty { dry, days } => match ops::empty(dry, days) { - Ok(_) => (), - Err(err) => eprintln!("error: {:?}", err), - }, + Command::Empty { dry, days } => ops::empty(dry, days), Command::List => { let home_trash = TrashDir::get_home_trash(); let mut files = home_trash @@ -72,12 +69,13 @@ fn main() -> Result<(), Error> { for info in files { println!("{}\t{}", info.deletion_date, info.path.to_str().unwrap()); } + Ok(()) } Command::Put { - paths, recursive, force - } => { - ops::put(paths, recursive); - } + paths, + recursive, + force, + } => ops::put(paths, recursive), Command::Restore => { let home_trash = TrashDir::get_home_trash(); let mut files = home_trash @@ -114,8 +112,19 @@ fn main() -> Result<(), Error> { } _ => println!("Invalid number."), } + Ok(()) + } + } +} + +fn main() { + match run() { + Ok(_) => (), + Err(err) => { + eprintln!("Error: {:?}", err); + for cause in err.chain() { + eprintln!("- {:?}", cause); + } } } - - Ok(()) } diff --git a/src/ops/empty.rs b/src/ops/empty.rs index 8be8b60..6d86f4b 100644 --- a/src/ops/empty.rs +++ b/src/ops/empty.rs @@ -1,12 +1,12 @@ use std::fs; -use anyhow::Error; +use anyhow::Result; use chrono::{Duration, Local}; use crate::TrashDir; use crate::TrashInfo; -pub fn empty(dry: bool, days: Option) -> Result<(), Error> { +pub fn empty(dry: bool, days: Option) -> Result<()> { let home_trash = TrashDir::get_home_trash(); let cutoff = if let Some(days) = days { Local::now() - Duration::days(days.into())