mod converter;
use crate::converter::*;
use argh::FromArgs;
use std::error::Error;
use std::path::PathBuf;
#[derive(FromArgs, Debug)]
struct Args {
#[argh(positional)]
input: String,
#[argh(option, short = 'o')]
output: Option<String>,
}
#[async_std::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let args: Args = argh::from_env();
let input_path = PathBuf::from(args.input.clone());
if input_path.is_file() {
let s = read_mjlog(&input_path)?;
if let Some(x) = args.output {
std::fs::write(x, s)?;
Ok(())
} else {
println!("{}", s);
Ok(())
}
} else if input_path.is_dir() {
let output_path = if let Some(x) = args.output { PathBuf::from(x) } else { input_path.clone() };
async_conv_dir(&input_path, &output_path).await
} else {
Err(format!("{} does not exist.", args.input).into())
}
}