diff --git a/Cargo.toml b/Cargo.toml index 70c6dfe8..2899ebe7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,12 @@ edition = "2021" readme = "README.md" authors = ["Christopher Berner "] keywords = ["fuse", "filesystem", "system", "bindings"] -categories = ["external-ffi-bindings", "api-bindings", "filesystem", "os::unix-apis"] +categories = [ + "external-ffi-bindings", + "api-bindings", + "filesystem", + "os::unix-apis", +] build = "build.rs" [dependencies] @@ -22,6 +27,7 @@ serde = { version = "1.0.102", features = ["std", "derive"], optional = true } smallvec = "1.6.1" zerocopy = { version = "0.7", features = ["derive"] } nix = { version = "0.28.0", features = ["fs", "user"] } +clap = { version = "4.4", optional = true } [dev-dependencies] env_logger = "0.11.3" diff --git a/src/mnt/mount_options.rs b/src/mnt/mount_options.rs index 1778d28e..f87b8cb8 100644 --- a/src/mnt/mount_options.rs +++ b/src/mnt/mount_options.rs @@ -1,5 +1,7 @@ +use std::convert::Infallible; use std::io; use std::io::ErrorKind; +use std::str::FromStr; use std::{collections::HashSet, ffi::OsStr}; /// Mount options accepted by the FUSE filesystem type @@ -86,6 +88,42 @@ impl MountOption { } } +impl FromStr for MountOption { + type Err = Infallible; + fn from_str(s: &str) -> Result { + Ok(Self::from_str(s)) + } +} + +#[cfg(feature = "clap")] +mod clap { + use ::clap::builder::{TypedValueParser, ValueParserFactory}; + use ::clap::error::ErrorKind; + use ::clap::{Arg, Command, Error}; + + use super::*; + #[derive(Clone, Copy, Debug)] + pub struct MountOptionParser; + impl TypedValueParser for MountOptionParser { + type Value = MountOption; + fn parse_ref( + &self, + _cmd: &Command, + _arg: Option<&Arg>, + value: &std::ffi::OsStr, + ) -> Result { + Ok(MountOption::from_str(&value.to_string_lossy())) + } + } + + impl ValueParserFactory for MountOption { + type Parser = MountOptionParser; + fn value_parser() -> Self::Parser { + MountOptionParser + } + } +} + pub fn check_option_conflicts(options: &[MountOption]) -> Result<(), io::Error> { let mut options_set = HashSet::new(); options_set.extend(options.iter().cloned());