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

use main_error for error printing

This commit is contained in:
Robin Appelman 2019-10-05 12:30:18 +02:00
commit 023d2c6f40
3 changed files with 171 additions and 116 deletions

View file

@ -1,12 +1,13 @@
use std::env;
use std::fs;
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Result, Stream};
use main_error::MainError;
pub use tf_demo_parser::{Demo, DemoParser, Parse, ParseError, ParserState, Stream};
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
fn main() -> std::result::Result<(), Box<ParseError>> {
fn main() -> Result<(), MainError> {
better_panic::install();
let args: Vec<_> = env::args().collect();
@ -19,14 +20,13 @@ fn main() -> std::result::Result<(), Box<ParseError>> {
.get(2)
.map(|arg| arg.as_str() == "all")
.unwrap_or_default();
let file = fs::read(path).expect("Unable to read file");
let file = fs::read(path)?;
let demo = Demo::new(file);
let (_, state) = if all {
DemoParser::parse_all(demo.get_stream())
} else {
DemoParser::parse_demo(demo.get_stream())
}?;
let json = serde_json::to_string(&state).unwrap_or("err".to_string());
println!("{}", json);
println!("{}", serde_json::to_string(&state)?);
Ok(())
}