palace 0.1.0

A tool for mounting datasets into memory for fast loading in deep learning tasks.
Documentation
use crate::mount::{mount_dataset, MountOptions};
use crate::unmount::{unmount_dataset, UnmountOptions};
use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Mount a dataset to memory
    Mount {
        /// Source directory of the dataset
        #[clap(short, long)]
        source: PathBuf,

        /// Destination directory for the mounted dataset
        #[clap(short, long)]
        destination: PathBuf,

        /// Number of parallel operations
        #[clap(short, long, default_value = "4")]
        parallel: usize,

        /// Use memory mapping instead of file copy
        #[clap(long)]
        mmap: bool,

        /// Compress data while mounting
        #[clap(short, long)]
        compress: bool,

        /// Memory threshold percentage (0-100)
        #[clap(short, long, default_value = "90")]
        threshold: u8,
    },

    /// Unmount a dataset from memory
    Unmount {
        /// Target directory of the mounted dataset
        #[clap(short, long)]
        target: PathBuf,

        /// Force unmount without confirmation
        #[clap(short, long)]
        force: bool,
    },
}

pub fn run() -> Result<()> {
    let cli = Cli::parse();

    match &cli.command {
        Commands::Mount {
            source,
            destination,
            parallel,
            mmap,
            compress,
            threshold,
        } => {
            let options = MountOptions {
                source: source.clone(),
                destination: destination.clone(),
                parallel: *parallel,
                use_mmap: *mmap,
                compress: *compress,
                memory_threshold: *threshold,
            };
            mount_dataset(&options)?;
            println!("Dataset mounted successfully.");
        }
        Commands::Unmount { target, force } => {
            let options = UnmountOptions {
                target: target.clone(),
                force: *force,
            };
            unmount_dataset(&options)?;
            println!("Dataset unmounted successfully.");
        }
    }

    Ok(())
}