From ceb507fd148916453b364be1fd1bd298e56176b1 Mon Sep 17 00:00:00 2001 From: =?utf8?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 | 79 +++++++++++++++++++++++++------------------------------------ 1 file changed, 32 insertions(+), 47 deletions(-) rewrite src/main.rs (71%) diff --git a/src/main.rs b/src/main.rs dissimilarity index 71% index 4a6f249..2189b51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,47 +1,32 @@ -use std::convert::TryFrom; - -mod cli; -mod error; -mod evaluator; -mod extension; -mod file; -mod test; -mod utils; - -mod compressors; -mod decompressors; - -fn main() -> error::OuchResult<()> { - let print_error = |err| { - println!("{}", 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); - - Ok(()) -} - -// 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(()) -// } +use std::convert::TryFrom; + +mod cli; +mod error; +mod evaluator; +mod extension; +mod file; +mod test; +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(); + let command = match cli::Command::try_from(matches) { + Ok(command) => command, + Err(err) => return Err(print_error(err)) + }; + + match Evaluator::evaluate(command) { + Ok(_) => Ok(()), + Err(err) => Err(print_error(err)) + } +} -- 2.11.4.GIT