2 collections::{BTreeMap, BTreeSet},
3 ffi::{OsStr, OsString},
6 /// Shallow type, created to indicate a `Flag` that accepts a argument.
8 /// ArgFlag::long(), is actually a Flag::long(), but sets a internal attribute.
10 /// Examples in here pls
15 pub fn long(name: &'static str) -> Flag {
24 #[derive(Debug, PartialEq, Clone)]
27 pub long: &'static str,
28 pub short: Option<char>,
29 pub takes_value: bool,
33 pub fn long(name: &'static str) -> Self {
41 pub fn short(mut self, short_flag_char: char) -> Self {
42 self.short = Some(short_flag_char);
47 #[derive(Default, PartialEq, Eq, Debug)]
49 pub boolean_flags: BTreeSet<&'static str>,
50 pub argument_flags: BTreeMap<&'static str, OsString>,
54 pub fn new() -> Self {
60 pub fn is_present(&self, flag_name: &str) -> bool {
61 self.boolean_flags.contains(flag_name) || self.argument_flags.contains_key(flag_name)
64 pub fn arg(&self, flag_name: &str) -> Option<&OsString> {
65 self.argument_flags.get(flag_name)
68 pub fn take_arg(&mut self, flag_name: &str) -> Option<OsString> {
69 self.argument_flags.remove(flag_name)
81 pub fn from(text: impl AsRef<OsStr>) -> Self {
82 let text = text.as_ref();
86 #[cfg(target_family = "unix")]
88 use std::os::unix::ffi::OsStrExt;
89 iter = text.as_bytes().iter();
91 #[cfg(target_family = "windows")]
93 use std::os::windows::ffi::OsStrExt;
94 iter = text.encode_wide
97 // 45 is the code for a hyphen
98 // Typed as 45_u16 for Windows
99 // Typed as 45_u8 for Unix
100 if let Some(45) = iter.next() {
101 if let Some(45) = iter.next() {