#![deny(warnings)]
use std::{
fs,
io::{self, Read},
};
use clap::Parser;
#[derive(Parser)]
#[command(name = "h2md")]
struct Cli {
input: Option<String>,
#[arg(short = 'o')]
output: Option<String>,
}
fn main() -> Result<(), h2md::Error> {
let cli = Cli::parse();
let html: Vec<u8> = match cli.input {
Some(ref path) => fs::read(path)?,
None => {
let mut buf = Vec::new();
io::stdin().read_to_end(&mut buf)?;
buf
}
};
if html.is_empty() {
return Ok(());
}
match cli.output {
Some(ref path) => {
let mut file = fs::File::create(path)?;
h2md::convert(&html, &mut file)?;
}
None => {
let stdout = io::stdout();
let mut handle = stdout.lock();
h2md::convert(&html, &mut handle)?;
}
}
Ok(())
}