novel_cli/cmd/
unzip.rs

1use std::path::PathBuf;
2
3use clap::Args;
4use color_eyre::eyre::Result;
5use fluent_templates::Loader;
6
7use crate::{LANG_ID, LOCALES, utils};
8
9#[must_use]
10#[derive(Args)]
11#[command(arg_required_else_help = true,
12    about = LOCALES.lookup(&LANG_ID, "unzip_command"))]
13pub struct Unzip {
14    #[arg(help = LOCALES.lookup(&LANG_ID, "epub_path"))]
15    pub epub_path: PathBuf,
16
17    #[arg(short, long, default_value_t = false,
18        help = LOCALES.lookup(&LANG_ID, "delete"))]
19    pub delete: bool,
20}
21
22pub fn execute(config: Unzip) -> Result<()> {
23    utils::ensure_epub_file(&config.epub_path)?;
24
25    super::unzip(&config.epub_path)?;
26
27    if config.delete {
28        utils::remove_file_or_dir(&config.epub_path)?;
29    }
30
31    Ok(())
32}