From ceb507fd148916453b364be1fd1bd298e56176b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Rodrigues=20Miguel?= Date: Thu, 25 Mar 2021 21:43:45 -0300 Subject: [PATCH] main: Make ouch return 1 upon failure --- src/main.rs | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a6f249..2189b51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,37 +11,22 @@ mod utils; mod compressors; mod decompressors; +use evaluator::Evaluator; + fn main() -> error::OuchResult<()> { let print_error = |err| { println!("{}", err); + err }; let matches = cli::get_matches(); - cli::Command::try_from(matches) - .map(|command| evaluator::Evaluator::evaluate(command).unwrap_or_else(print_error)) - .unwrap_or_else(print_error); + let command = match cli::Command::try_from(matches) { + Ok(command) => command, + Err(err) => return Err(print_error(err)) + }; - Ok(()) + match Evaluator::evaluate(command) { + Ok(_) => Ok(()), + Err(err) => Err(print_error(err)) + } } - -// fn main() -> error::OuchResult<()> { -// use tar::{Builder}; -// use walkdir::WalkDir; -// -// let mut b = Builder::new(Vec::new()); -// -// for entry in WalkDir::new("src") { -// let entry = entry?; -// let mut file = std::fs::File::open(entry.path())?; -// b.append_file(entry.path(), &mut file)?; -// } -// -// // let mut file = std::fs::File::open("Cargo.toml")?; -// // b.append_file("Cargo.toml", &mut file)?; -// -// let bytes = b.into_inner()?; -// -// std::fs::write("daaaaamn.tar", bytes)?; -// -// Ok(()) -// }