fn parse_flags(&self, tokens: std::str::SplitWhitespace) -> Option<HashMap<String, String>> {
        let mut parsed_flags = HashMap::new();
        let mut flag = String::new();
        let mut flag_value;

        for token in tokens {
            if token.starts_with(FLAG_PREFIX) {
                flag = token.to_string().replace("-", "");
                if parsed_flags.contains_key(&flag) {
                    //We shouldn't have a flag twice
                    println!("Flag {} has been discovered twice", flag);
                    return None;
                } 
                else {
                    //Add the discovered flag
                    parsed_flags.insert(flag.clone(), String::default());
                }
            }
            else {
                flag_value = token.to_string();
                let wrapped_stored_flag_value = parsed_flags.get_key_value(&flag);
                if wrapped_stored_flag_value.is_some() {
                    if wrapped_stored_flag_value.unwrap().1 == &String::new() {
                        //Set the value for the flag
                        parsed_flags.remove_entry(&flag);
                        parsed_flags.insert(flag.clone(), flag_value);
                    }
                    else {
                        //Flags shouldn't have two values
                        println!("Flag {} already has a value", flag);
                        return None;
                    }
                }
                else {
                    println!("Expected a flag, instead found: {}", flag_value);
                }
            }
        }
        return Some(parsed_flags);
    }
/// Parses the specified tokens for flags and their values.
/// Returns the flags as a HashMap<String, String>
Parses the specified tokens for flags and their values.
Returns the flags as a HashMap
Parses the specified tokens for flags and their values . Returns the flags as a HashMap
fn parse_flags(&self, tokens: std::str::SplitWhitespace) -> Option<HashMap<String, String>> {
        let mut parsed_flags = HashMap::new();
        let mut flag = String::new();
        let mut flag_value;
        for token in tokens {
            if token.starts_with(FLAG_PREFIX) {
                flag = token.to_string().replace("-", "");
                if parsed_flags.contains_key(&flag) {
                    //We shouldn't have a flag twice
                    println!("Flag {} has been discovered twice", flag);
                    return None;
                } 
                else {
                    //Add the discovered flag
                    parsed_flags.insert(flag.clone(), String::default());
                }
            }
            else {
                flag_value = token.to_string();
                let wrapped_stored_flag_value = parsed_flags.get_key_value(&flag);
                if wrapped_stored_flag_value.is_some() {
                    if wrapped_stored_flag_value.unwrap().1 == &String::new() {
                        //Set the value for the flag
                        parsed_flags.remove_entry(&flag);
                        parsed_flags.insert(flag.clone(), flag_value);
                    }
                    else {
                        //Flags shouldn't have two values
                        println!("Flag {} already has a value", flag);
                        return None;
                    }
                }
                else {
                    println!("Expected a flag, instead found: {}", flag_value);
                }
            }
        }
        return Some(parsed_flags);
    }
fn parse_flags ( & self , tokens : std :: str :: SplitWhitespace ) -> Option < HashMap < String , String > > { let mut parsed_flags = HashMap :: new ( ) ; let mut flag = String :: new ( ) ; let mut flag_value ; for token in tokens { if token . starts_with ( FLAG_PREFIX ) { flag = token . to_string ( ) . replace ( " " , " " ) ; if parsed_flags . contains_key ( & flag ) { //We shouldn't have a flag twice println ! ( " " flag ) ; return None ; } else { //Add the discovered flag parsed_flags . insert ( flag . clone ( ) , String :: default ( ) ) ; } } else { flag_value = token . to_string ( ) ; let wrapped_stored_flag_value = parsed_flags . get_key_value ( & flag ) ; if wrapped_stored_flag_value . is_some ( ) { if wrapped_stored_flag_value . unwrap ( ) . 1 == & String :: new ( ) { //Set the value for the flag parsed_flags . remove_entry ( & flag ) ; parsed_flags . insert ( flag . clone ( ) , flag_value ) ; } else { //Flags shouldn't have two values println ! ( " " flag ) ; return None ; } } else { println ! ( " " flag_value ) ; } } } return Some ( parsed_flags ) ; }
Parses the specified tokens for flags and their values.
Parses the specified tokens for flags and their values .
&self
tokens
std::str::SplitWhitespace
&self
tokens
std::str::SplitWhitespace