1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 18:24:05 +02:00

take path from argument

This commit is contained in:
Robin Appelman 2019-03-05 21:33:11 +01:00
commit 0b331c83e2

View file

@ -1,18 +1,21 @@
#[allow(unused_variables)]
use std::error::Error;
use std::fs;
use std::env;
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Result, Stream};
fn main() -> std::result::Result<(), Box<ParseError>> {
let file = fs::read("data/ash.dem").expect("Unable to read file");
let args: Vec<_> = env::args().collect();
if args.len() < 2{
panic!("1 argument required");
}
let path = args[1].clone();
let file = fs::read(path).expect("Unable to read file");
let demo = Demo::new(file);
let stream: Stream = demo.get_stream();
let mut parser = DemoParser::new(stream);
let (header, state) = parser.parse_demo()?;
//dbg!(header);
//dbg!(state.deaths);
//std::thread::sleep(std::time::Duration::from_secs(5));
let json = serde_json::to_string(&state).unwrap_or("err".to_string());
println!("{}", json);
Ok(())