mod error;
mod execute;
mod ini;
mod io;
mod parse;
mod parse_util;
mod signature;
mod types;
use std::io::Write;
use std::process::ExitCode;
use types::Args;
pub fn run() -> ExitCode {
let args = match Args::parse() {
Ok(args) => args,
Err(e) => {
eprintln!("Error: {e}");
return ExitCode::FAILURE;
}
};
if let Some(ref path) = args.error_log {
let _ = std::fs::write(path, "");
}
if let Err(e) = args.execute() {
if let Some(ref path) = args.error_log {
let _ = std::fs::write(path, format!("{e}"));
}
if !args.silent {
eprintln!("Error: {e}");
}
return ExitCode::FAILURE;
}
if args.write_version
&& let Some(ref path) = args.error_log
{
let mut file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(path);
if let Ok(ref mut file) = file {
let _ = write!(file, "Hexview V{}", env!("CARGO_PKG_VERSION"));
}
}
ExitCode::SUCCESS
}