use adif_io::{DeserializeADI, Doc};
use clap::Parser;
use env_logger;
use log::info;
use std::{env, fs};
#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
#[arg(short, long, default_value = "test_data/big_testfile_1000.adi")]
file: String,
#[arg(short, long)]
out: Option<String>,
}
fn main() {
let _ = env::var("RUST_LOG").is_err_and(|_| {
unsafe { env::set_var("RUST_LOG", "info") }
false
});
env_logger::init();
let args = Args::parse();
info!("Reading ADI file '{}'...", &args.file);
let content = fs::read_to_string(args.file).expect("error reading ADI file: {err}");
let mut doc = Doc::new();
doc.deserialize_adi(&content)
.expect("could not deserialize from ADI");
let json = serde_json::to_string_pretty(&doc).expect("could not serialize to JSON");
if let Some(out) = args.out {
info!("Writing JSON file '{}'...", &out);
fs::write(out, json).expect("could not write JSON output file");
} else {
println!("{json}");
}
}