use std::io::Read;
use std::path::PathBuf;
use std::{env, fs::File};
use vita49::prelude::*;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
panic!("error - pass a JSON5 file");
}
let mut path = PathBuf::from(&args[1]);
let mut input = match std::fs::File::open(&path) {
Ok(file) => Box::new(file),
Err(err) => {
panic!("{}: {}", path.to_string_lossy(), err);
}
};
let mut json = String::new();
input
.read_to_string(&mut json)
.expect("failed to read string from file");
let packet: Vrt = serde_json5::from_str(&json).expect("failed to parse JSON into VRT");
let _ = path.set_extension("vrt");
let file = File::options()
.write(true)
.create(true)
.open(&path)
.expect("failed to open VRT file");
packet
.to_writer(&mut Writer::new(file), ())
.expect("failed to write VRT file");
println!("Wrote VRT data to {}", path.to_string_lossy());
}