Add slightly interactive main function

This commit is contained in:
Joakim Soderlund 2019-07-21 17:13:43 +00:00
parent f50f5bd65c
commit d1f9f588d5
2 changed files with 26 additions and 1 deletions

View file

@ -4,6 +4,7 @@
pub enum Error { pub enum Error {
InvalidStory(), InvalidStory(),
SourceError(&'static str), SourceError(&'static str),
UserError(&'static str),
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View file

@ -5,6 +5,30 @@ pub mod fetcher;
pub mod parser; pub mod parser;
pub mod story; 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::<Vec<String>>();
let path = match argv.len() {
2 => Ok(argv.get(1).unwrap()),
_ => Err(UserError("Usage: fimfareader <ARCHIVE>")),
}?;
println!("Hellopaca, World!"); 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(())
} }