mirror of
https://github.com/JockeTF/fimfareader.git
synced 2024-11-27 07:28:00 +01:00
Simplify CLI module using dynamic error returns
This commit is contained in:
parent
5a967c8445
commit
314b388c35
1 changed files with 9 additions and 15 deletions
|
@ -1,20 +1,15 @@
|
||||||
//! Main module.
|
//! Main module.
|
||||||
|
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::result::Result;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use rustyline::DefaultEditor;
|
use fimfareader::archive::Fetcher;
|
||||||
use rustyline::Result;
|
|
||||||
|
|
||||||
use fimfareader::prelude::*;
|
|
||||||
use fimfareader_query::parse;
|
use fimfareader_query::parse;
|
||||||
|
use rustyline::DefaultEditor;
|
||||||
|
|
||||||
fn exit(error: Error) -> ! {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
eprintln!("{}", error);
|
|
||||||
std::process::exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
let mut editor = DefaultEditor::new()?;
|
let mut editor = DefaultEditor::new()?;
|
||||||
|
|
||||||
|
@ -26,13 +21,12 @@ fn main() -> Result<()> {
|
||||||
println!("Hellopaca, World!");
|
println!("Hellopaca, World!");
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let result = Fetcher::new(&argv[1]);
|
let fetcher = Fetcher::new(&argv[1])?;
|
||||||
let fetcher = result.map_err(exit).unwrap();
|
let finish = Instant::now() - start;
|
||||||
let finish = (Instant::now() - start).as_millis();
|
|
||||||
let count = fetcher.iter().count();
|
let count = fetcher.iter().count();
|
||||||
|
|
||||||
println!("Finished loading in {} milliseconds.", finish);
|
println!("Finished loading in {finish:?}.");
|
||||||
println!("The archive contains {} stories.", count);
|
println!("The archive contains {count} stories.");
|
||||||
|
|
||||||
while let Ok(line) = editor.readline(">>> ") {
|
while let Ok(line) = editor.readline(">>> ") {
|
||||||
editor.add_history_entry(&line)?;
|
editor.add_history_entry(&line)?;
|
||||||
|
|
Loading…
Reference in a new issue