use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "hwp2md")]
#[command(about = "HWP/HWPX ↔ Markdown bidirectional converter")]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, default_value = "info")]
log_level: String,
}
#[derive(Subcommand)]
enum Commands {
ToMd {
input: PathBuf,
#[arg(short, long)]
output: Option<PathBuf>,
#[arg(long)]
assets_dir: Option<PathBuf>,
#[arg(long)]
frontmatter: bool,
},
ToHwpx {
input: PathBuf,
#[arg(short, long)]
output: Option<PathBuf>,
#[arg(long)]
style: Option<PathBuf>,
},
Info {
input: PathBuf,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_env_filter(&cli.log_level)
.init();
match cli.command {
Commands::ToMd {
input,
output,
assets_dir,
frontmatter,
} => {
hwp2md::convert::to_markdown(
&input,
output.as_deref(),
assets_dir.as_deref(),
frontmatter,
)?;
}
Commands::ToHwpx {
input,
output,
style,
} => {
hwp2md::convert::to_hwpx(&input, output.as_deref(), style.as_deref())?;
}
Commands::Info { input } => {
hwp2md::convert::show_info(&input)?;
}
}
Ok(())
}