use clap::Parser;
use htmltoadf::convert_html_str_to_adf_str;
use std::fs;
use std::io::stdin;
use std::io::Read;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(parse(from_os_str))]
inpath: Option<std::path::PathBuf>,
#[clap(short, long)]
outpath: Option<std::path::PathBuf>,
}
fn main() {
let cli = Cli::parse();
let adf = if let Some(config_path) = cli.inpath.as_deref() {
let contents =
fs::read_to_string(config_path).expect("Something went wrong reading the input file");
convert_html_str_to_adf_str(contents)
} else {
convert_html_str_to_adf_str(read_html())
};
if let Some(outpath) = cli.outpath.as_deref() {
fs::write(outpath, adf).expect("Something went wrong writing output file");
} else {
println!("{adf}");
};
}
pub fn read_html() -> String {
let mut html = String::new();
stdin()
.lock()
.read_to_string(&mut html)
.expect("Read from STDIN failed");
html
}