add better panic message and restructure src/args.rs

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-04-08 02:10:36 +05:30
parent 57ce926af6
commit 6979a02408
3 changed files with 68 additions and 36 deletions

View File

@@ -1,6 +1,28 @@
use tricc::args;
use std::fs;
use std::panic;
use tricc::args::Args;
fn main() {
let file: String = args::handle();
println!("{}", file);
panic::set_hook(Box::new(|panic_info| {
if let Some(msg) = panic_info.payload().downcast_ref::<&str>() {
eprintln!("{}", msg);
} else if let Some(msg) = panic_info.payload().downcast_ref::<String>() {
eprintln!("{}", msg);
} else if let Some(location) = panic_info.location() {
eprintln!(
"panic occurred in file '{}' at line {}",
location.file(),
location.line(),
);
} else {
eprintln!("panic occurred");
}
}));
let mut args = Args::new();
args.handle();
let file = args.get_file();
let contents = fs::read_to_string(&file).expect("Couldn't read the file");
}