pub fn search_in_path(&mut self, command: &str) -> Result<PathBuf, ShellError> {
        if let Some(path) = self.contains_cmd(command) {
            println!("Got path {:?} from internal hashmap", path);
            return Ok(path.into())
        }
        //collecting all entries in $PATH
        let paths: Vec<PathBuf> = env::var("PATH")
            .unwrap_or(String::new())
            .split(":")
            .map(|n| PathBuf::from(n))
            .collect();
        if paths.is_empty() {
            return Err(ShellError::from("oyster: path is empty"))
        }
        for path in paths {
            //iterating over all the entries in the path
            for item in std::fs::read_dir(path)? {
                let item = item?;
                //getting the file name of the entry path
                if let Some(entry) = item.path().file_name() {
                    let entry = entry.to_str()
                        .ok_or(ShellError::from("oyster: error converting filepaths"))?;
                    if entry == command {
                        self.add_cmd(command, entry);
                        return Ok(item.path())
                    } else {
                        continue
                    }
                } else {
                    return Err(ShellError::from(
                        format!("oyster: error")
                    ))
                }
            }
        }
        Err(ShellError::from(format!("oyster: command `{}` not found", command)))
    }
/// Searches PATH for the required program file.
Searches PATH for the required program file.
Searches PATH for the required program file .
pub fn search_in_path(&mut self, command: &str) -> Result<PathBuf, ShellError> {
        if let Some(path) = self.contains_cmd(command) {
            println!("Got path {:?} from internal hashmap", path);
            return Ok(path.into())
        }
        //collecting all entries in $PATH
        let paths: Vec<PathBuf> = env::var("PATH")
            .unwrap_or(String::new())
            .split(":")
            .map(|n| PathBuf::from(n))
            .collect();
        if paths.is_empty() {
            return Err(ShellError::from("oyster: path is empty"))
        }
        for path in paths {
            //iterating over all the entries in the path
            for item in std::fs::read_dir(path)? {
                let item = item?;
                //getting the file name of the entry path
                if let Some(entry) = item.path().file_name() {
                    let entry = entry.to_str()
                        .ok_or(ShellError::from("oyster: error converting filepaths"))?;
                    if entry == command {
                        self.add_cmd(command, entry);
                        return Ok(item.path())
                    } else {
                        continue
                    }
                } else {
                    return Err(ShellError::from(
                        format!("oyster: error")
                    ))
                }
            }
        }
        Err(ShellError::from(format!("oyster: command `{}` not found", command)))
    }
pub fn search_in_path ( & mut self , command : & str ) -> Result < PathBuf , ShellError > { if let Some ( path ) = self . contains_cmd ( command ) { println ! ( " " path ) ; return Ok ( path . into ( ) ) } //collecting all entries in $PATH let paths : Vec < PathBuf > = env :: var ( " " ) . unwrap_or ( String :: new ( ) ) . split ( " " ) . map ( | n | PathBuf :: from ( n ) ) . collect ( ) ; if paths . is_empty ( ) { return Err ( ShellError :: from ( " " ) ) } for path in paths { //iterating over all the entries in the path for item in std :: fs :: read_dir ( path ) ? { let item = item ? ; //getting the file name of the entry path if let Some ( entry ) = item . path ( ) . file_name ( ) { let entry = entry . to_str ( ) . ok_or ( ShellError :: from ( " " ) ) ? ; if entry == command { self . add_cmd ( command , entry ) ; return Ok ( item . path ( ) ) } else { continue } } else { return Err ( ShellError :: from ( format ! ( " " ) ) ) } } } Err ( ShellError :: from ( format ! ( " " command ) ) ) }
Searches PATH for the required program file.
Searches PATH for the required program file .
&mut self
command
&str