Skip to main content

wordchipper_cli_util/
disk_cache.rs

1use wordchipper::disk_cache::{
2    WordchipperDiskCache,
3    WordchipperDiskCacheOptions,
4};
5
6/// Disk cache argument group.
7#[derive(clap::Args, Debug)]
8pub struct DiskCacheArgs {
9    /// Cache directory.
10    #[arg(long, default_value = None)]
11    cache_dir: Option<String>,
12}
13
14impl DiskCacheArgs {
15    /// Initialize the disk cache.
16    pub fn init_disk_cache(&self) -> Result<WordchipperDiskCache, Box<dyn std::error::Error>> {
17        let mut options = WordchipperDiskCacheOptions::default();
18
19        if let Some(cache_dir) = &self.cache_dir {
20            options = options.with_cache_dir(Some(cache_dir.clone()));
21        }
22
23        WordchipperDiskCache::new(options)
24    }
25}