use std::path::PathBuf;
use clap::Args;
use color_eyre::eyre::Result;
use fluent_templates::Loader;
use novel_api::Timing;
use tracing::debug;
use crate::{utils, LANG_ID, LOCALES};
#[must_use]
#[derive(Args)]
#[command(arg_required_else_help = true,
about = LOCALES.lookup(&LANG_ID, "unzip_command"))]
pub struct Unzip {
#[arg(help = LOCALES.lookup(&LANG_ID, "epub_path"))]
pub epub_path: PathBuf,
#[arg(short, long, default_value_t = false,
help = LOCALES.lookup(&LANG_ID, "delete"))]
pub delete: bool,
}
pub fn execute(config: Unzip) -> Result<()> {
let mut timing = Timing::new();
utils::ensure_epub_file(&config.epub_path)?;
super::unzip(&config.epub_path)?;
if config.delete {
utils::remove_file_or_dir(&config.epub_path)?;
}
debug!("Time spent on `unzip`: {}", timing.elapsed()?);
Ok(())
}