use crate::args::ConvertArgs;
use crate::utils::read_input;
use std::str::FromStr;
pub fn handle_convert(args: ConvertArgs) {
let (input, _label) = match read_input(&args.file) {
Ok(res) => res,
Err(e) => {
eprintln!("Error reading input: {}", e);
std::process::exit(1);
}
};
let from_fmt = match jsonette::converter::DataFormat::from_str(&args.from) {
Ok(f) => f,
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
};
let to_fmt = match jsonette::converter::DataFormat::from_str(&args.to) {
Ok(f) => f,
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
};
match jsonette::converter::convert(&input, from_fmt, to_fmt) {
Ok(output) => {
println!("{}", output);
}
Err(e) => {
eprintln!("Conversion error: {}", e);
std::process::exit(1);
}
}
}