Skip to main content

palacex/
cli.rs

1use crate::mount::{mount_dataset, MountOptions};
2use crate::unmount::{unmount_dataset, UnmountOptions};
3use anyhow::Result;
4use clap::{Parser, Subcommand};
5use std::path::PathBuf;
6
7#[derive(Parser)]
8#[clap(author, version, about, long_about = None)]
9struct Cli {
10    #[clap(subcommand)]
11    command: Commands,
12}
13
14#[derive(Subcommand)]
15enum Commands {
16    /// Mount a dataset to memory
17    Mount {
18        /// Source directory of the dataset
19        #[clap(short, long)]
20        source: PathBuf,
21
22        /// Destination directory for the mounted dataset
23        #[clap(short, long)]
24        destination: PathBuf,
25
26        /// Number of parallel operations
27        #[clap(short, long, default_value = "4")]
28        parallel: usize,
29
30        /// Use memory mapping instead of file copy
31        #[clap(long)]
32        mmap: bool,
33
34        /// Compress data while mounting
35        #[clap(short, long)]
36        compress: bool,
37
38        /// Memory threshold percentage (0-100)
39        #[clap(short, long, default_value = "90")]
40        threshold: u8,
41    },
42
43    /// Unmount a dataset from memory
44    Unmount {
45        /// Target directory of the mounted dataset
46        #[clap(short, long)]
47        target: PathBuf,
48
49        /// Force unmount without confirmation
50        #[clap(short, long)]
51        force: bool,
52    },
53}
54
55pub fn run() -> Result<()> {
56    let cli = Cli::parse();
57
58    match &cli.command {
59        Commands::Mount {
60            source,
61            destination,
62            parallel,
63            mmap,
64            compress,
65            threshold,
66        } => {
67            let options = MountOptions {
68                source: source.clone(),
69                destination: destination.clone(),
70                parallel: *parallel,
71                use_mmap: *mmap,
72                compress: *compress,
73                memory_threshold: *threshold,
74            };
75            mount_dataset(&options)?;
76            println!("Dataset mounted successfully.");
77        }
78        Commands::Unmount { target, force } => {
79            let options = UnmountOptions {
80                target: target.clone(),
81                force: *force,
82            };
83            unmount_dataset(&options)?;
84            println!("Dataset unmounted successfully.");
85        }
86    }
87
88    Ok(())
89}