From d1f9f588d50bc7a9f58b17624b5784b9623b3e3b Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Sun, 21 Jul 2019 17:13:43 +0000 Subject: [PATCH] Add slightly interactive main function --- src/error.rs | 1 + src/main.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 4996c44..753c596 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,6 +4,7 @@ pub enum Error { InvalidStory(), SourceError(&'static str), + UserError(&'static str), } pub type Result = std::result::Result; diff --git a/src/main.rs b/src/main.rs index 43f06fd..0c8fedf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,30 @@ pub mod fetcher; pub mod parser; pub mod story; -fn main() { +use std::env::args; +use std::time::Instant; + +use crate::error::{Error, Result}; +use crate::fetcher::Fetcher; + +fn main() -> Result<()> { + use Error::*; + + let argv = args().collect::>(); + + let path = match argv.len() { + 2 => Ok(argv.get(1).unwrap()), + _ => Err(UserError("Usage: fimfareader ")), + }?; + println!("Hellopaca, World!"); + + let start = Instant::now(); + let fetcher = Fetcher::from(path)?; + let finish = Instant::now() - start; + + println!("Finished loading in {} milliseconds.", finish.as_millis()); + println!("The archive contains {} stories.", fetcher.iter().count()); + + Ok(()) }