pub mod builder;
pub mod legacy_argument;
pub mod parsable_argument;
#[derive(Debug)]
pub enum ArgumentIdentification {
Short(char),
Long(String),
Both(char, String),
}
impl ArgumentIdentification {
pub fn is_by_short(&self, name: char) -> bool {
if let ArgumentIdentification::Short(c) = self {
return c == &name;
}
if let ArgumentIdentification::Both(c, _) = self {
return c == &name;
}
false
}
pub fn is_by_long(&self, name: &str) -> bool {
if let ArgumentIdentification::Long(s) = &self {
return s == name;
}
if let ArgumentIdentification::Both(_, s) = &self {
return s == name;
}
false
}
}
#[cfg(test)]
mod test {
use super::ArgumentIdentification;
#[test]
fn is_by_short_works() {
let short_id = ArgumentIdentification::Short('x');
assert!(short_id.is_by_short('x'));
assert!(!short_id.is_by_short('c'));
let both_id = ArgumentIdentification::Both('z', String::from("directory"));
assert!(both_id.is_by_short('z'));
assert!(!both_id.is_by_short('c'));
}
#[test]
fn is_by_long_works() {
let short_id = ArgumentIdentification::Long(String::from("path"));
assert!(short_id.is_by_long("path"));
assert!(!short_id.is_by_long("name"));
let both_id = ArgumentIdentification::Both('z', String::from("file"));
assert!(both_id.is_by_long("file"));
assert!(!both_id.is_by_long("bar"));
}
}