pub mod remote_host;
use anyhow::{anyhow, Context};
use clap::Parser;
use std::path::PathBuf;
use remote_host::RemoteName;
#[derive(Parser, Debug)]
#[command(author, version, about)]
pub struct Opt {
pub remote: RemoteName,
#[arg(value_parser = exist_dir)]
pub mount_point: String,
#[arg(short = 'F', long)]
pub config_file: Option<PathBuf>,
#[arg(short, long)]
pub login_name: Option<String>,
#[arg(short, long)]
pub identity: Option<PathBuf>,
#[arg(short, long)]
pub port: Option<u16>,
#[arg(short, long)]
pub readonly: bool,
#[arg(long)]
pub no_exec: bool,
#[arg(long)]
pub no_atime: bool,
#[arg(short, long)]
pub daemon: bool,
}
fn exist_dir(s: &str) -> anyhow::Result<String> {
match std::fs::read_dir(s) {
Ok(mut dir) => match dir.next() {
None => Ok(s.to_string()),
Some(_) => Err(anyhow!("Mount destination directory is not empty.")),
},
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => Err(anyhow!("The mount directory does not exist.")),
std::io::ErrorKind::NotConnected => Err(anyhow!(
"The network of the mount directory is disconnected. (Did you forget to umount?)."
)),
_ => Err(e).context("Unexpected error.(check mount directory)"),
},
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn verify_cli() {
use clap::CommandFactory;
Opt::command().debug_assert()
}
}