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:
parent
4fcc110a0f
commit
023d2c6f40
3 changed files with 171 additions and 116 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue