/// Parse a string to get a PromptCommand. If the parse fails,
/// None is returned.
Parse a string to get a PromptCommand. If the parse fails,
None is returned.
Parse a string to get a PromptCommand . If the parse fails None is returned .
pub fn parse(s: &'a str) -> Option<PromptCommand<'a>> {
        use self::PromptCommand::*;
        let mut split = s.split(' ');
        let base_cmd = split.nth(0).unwrap_or("");
        let sec_cmd = split.nth(0).unwrap_or("");
        Some(match base_cmd {
            "set" => Set { option: sec_cmd },
            "unset" => Unset { option: sec_cmd },
            "toggle" | "tog" => Toggle { option: sec_cmd },
            "get" => Get { option: sec_cmd },
            "o" | "open" => Open { path: sec_cmd },
            "w" | "write" => Write { path: sec_cmd },
            "ls" => ListBuffers,
            "bn" => CreateBuffer,
            "bd" => DeleteBuffer,
            "h" | "help" => Help,
            "q" | "quit" => Quit,
            bn if bn.starts_with("b") => {
                let rest: String = bn.chars().skip(1).collect();
                if let Ok(number) = rest.parse::<usize>() {
                    SwitchToBuffer {
                        buffer_index: number,
                    }
                } else {
                    return None;
                }
            }
            _ => return None,
        })
    }
pub fn parse ( s : & ' a str ) -> Option < PromptCommand < ' a > > { use self :: PromptCommand :: * ; let mut split = s . split ( ' ' ) ; let base_cmd = split . nth ( 0 ) . unwrap_or ( " " ) ; let sec_cmd = split . nth ( 0 ) . unwrap_or ( " " ) ; Some ( match base_cmd { " " => Set { option : sec_cmd } , " " => Unset { option : sec_cmd } , " " | " " => Toggle { option : sec_cmd } , " " => Get { option : sec_cmd } , " " | " " => Open { path : sec_cmd } , " " | " " => Write { path : sec_cmd } , " " => ListBuffers , " " => CreateBuffer , " " => DeleteBuffer , " " | " " => Help , " " | " " => Quit , bn if bn . starts_with ( " " ) => { let rest : String = bn . chars ( ) . skip ( 1 ) . collect ( ) ; if let Ok ( number ) = rest . parse :: < usize > ( ) { SwitchToBuffer { buffer_index : number , } } else { return None ; } } _ => return None , } ) }
Parse a string to get a PromptCommand.
Parse a string to get a PromptCommand .
s
&'a str