From 314b388c350965bc562eb399b00dd151e6f80f11 Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Wed, 29 May 2024 17:25:08 +0200 Subject: [PATCH] Simplify CLI module using dynamic error returns --- cli/src/main.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 432376c..1a84bf7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,20 +1,15 @@ //! Main module. use std::env::args; +use std::error::Error; +use std::result::Result; use std::time::Instant; -use rustyline::DefaultEditor; -use rustyline::Result; - -use fimfareader::prelude::*; +use fimfareader::archive::Fetcher; use fimfareader_query::parse; +use rustyline::DefaultEditor; -fn exit(error: Error) -> ! { - eprintln!("{}", error); - std::process::exit(1) -} - -fn main() -> Result<()> { +fn main() -> Result<(), Box> { let argv = args().collect::>(); let mut editor = DefaultEditor::new()?; @@ -26,13 +21,12 @@ fn main() -> Result<()> { println!("Hellopaca, World!"); let start = Instant::now(); - let result = Fetcher::new(&argv[1]); - let fetcher = result.map_err(exit).unwrap(); - let finish = (Instant::now() - start).as_millis(); + let fetcher = Fetcher::new(&argv[1])?; + let finish = Instant::now() - start; let count = fetcher.iter().count(); - println!("Finished loading in {} milliseconds.", finish); - println!("The archive contains {} stories.", count); + println!("Finished loading in {finish:?}."); + println!("The archive contains {count} stories."); while let Ok(line) = editor.readline(">>> ") { editor.add_history_entry(&line)?;