novel-cli 0.17.0

A set of tools for downloading novels from the web, manipulating text, and generating EPUB
Documentation
use std::path::PathBuf;

use clap::Args;
use color_eyre::eyre::Result;
use fluent_templates::Loader;

use crate::{LANG_ID, LOCALES, utils};

#[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<()> {
    utils::ensure_epub_file(&config.epub_path)?;

    super::unzip(&config.epub_path)?;

    if config.delete {
        utils::remove_file_or_dir(&config.epub_path)?;
    }

    Ok(())
}