use anyhow::Result;
use clap::{Parser, Subcommand};
use env_logger;
use froggr::modules::namespace::BindMode;
use froggr::FilesystemManager;
use froggr::NineP;
use log::info;
use std::path::PathBuf;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Bind {
#[arg(short = 'b', long = "before", group = "bind_mode")]
before: bool,
#[arg(short = 'a', long = "after", group = "bind_mode")]
after: bool,
#[arg(short = 'r', long = "replace", group = "bind_mode")]
replace: bool,
#[arg(short = 'c', long = "create", group = "bind_mode")]
create: bool,
source: PathBuf,
target: PathBuf,
},
Mount {
source: PathBuf,
mount_point: PathBuf,
#[arg(default_value = "localhost")]
node_id: String,
},
}
#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();
let cli = Cli::parse();
match &cli.command {
Commands::Bind {
before,
after,
replace,
create,
source,
target,
} => {
let bind_mode = match (before, after, replace, create) {
(_, _, true, _) => BindMode::Replace,
(_, _, _, true) => BindMode::Create,
(_, true, _, _) => BindMode::After,
_ => BindMode::Before,
};
let hello_fs = NineP::new(target.clone())?;
let fs_mngr = FilesystemManager::new(hello_fs);
fs_mngr.bind(source.as_path(), target.as_path(), bind_mode)?;
info!(
"Successfully bound {} to {}",
source.display(),
target.display()
);
}
Commands::Mount {
source,
mount_point,
node_id,
} => {
let hello_fs = NineP::new(source.clone())?;
let fs_mngr = FilesystemManager::new(hello_fs);
fs_mngr.mount(&source.as_path(), &mount_point.as_path(), &node_id)?;
info!(
"Successfully mounted {} to {}",
source.display(),
mount_point.display()
);
}
}
Ok(())
}