use clap::Parser;
use xlsbye_core::types::OutputFormat;
use xlsbye_transcoder::detect::detect_output_format_from_path;
#[derive(Parser)]
#[command(name = "xlsbye", version, about = "Convert XLSB files to XLSX/XLSM")]
struct Cli {
input: std::path::PathBuf,
#[arg(short, long)]
output: Option<std::path::PathBuf>,
#[arg(short, long, default_value_t = false)]
verbose: bool,
}
fn main() {
let cli = Cli::parse();
if cli.verbose {
tracing_subscriber::fmt()
.with_env_filter("xlsbye=debug")
.init();
} else {
tracing_subscriber::fmt()
.with_env_filter("xlsbye=warn")
.init();
}
let output = match cli.output {
Some(path) => path,
None => default_output_path(&cli.input),
};
match xlsbye_transcoder::pipeline::convert(&cli.input, &output) {
Ok(()) => {
eprintln!("Converted: {} -> {}", cli.input.display(), output.display());
}
Err(e) => {
eprintln!("Error: {e}");
std::process::exit(1);
}
}
}
fn default_output_path(input: &std::path::Path) -> std::path::PathBuf {
let detected = detect_output_format_from_path(input)
.unwrap_or(OutputFormat::Xlsx);
let ext = match detected {
OutputFormat::Xlsx => "xlsx",
OutputFormat::Xlsm => "xlsm",
};
input.with_extension(ext)
}