use alixt::{models::cli::Args, utils};
use clap::Parser;
use std::process::exit;
#[tokio::main]
async fn main() {
let mut args = Args::parse();
let mut writer: Box<dyn std::io::Write> = if args.output.is_some() {
let file = match std::fs::File::create(args.output.take().unwrap()) {
Ok(file) => file,
Err(e) => {
eprintln!("Error: {e:#?}");
exit(1);
},
};
Box::new(file)
} else {
Box::new(std::io::stdout())
};
if args.generate_template {
if let Err(e) = utils::template::generate(&mut writer) {
eprintln!("Error generating template file: {e:#?}");
exit(1)
} else {
exit(0)
}
}
match alixt::run(&mut writer, args).await {
Ok(_) => exit(0),
Err(e) => {
eprintln!("Error: {e}");
exit(1);
}
}
}