Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn parse(mut input: Vec<Token>)-> Result<(), Box<dyn std::error::Error>> {
- while let Some((index, item)) = input.iter().enumerate().next() {
- "cd" => {
- println!("cd");
- let dir = Path::new(input.peekable()
- .peek()
- .map_or("/", |val| *val));
- // try to set to new dir, otherwise root
- if let Err(e) = env::set_current_dir(&dir) {
- return Err(Box::from(e))
- }
- else {
- return Ok(())
- }
- },
- "exit" | "q" => {
- std::process::exit(1);
- },
- command => {
- println!("command");
- let mut child = Command::new(command)
- .args(input)
- .spawn()?;
- let code = child.wait();
- if code.is_err(){
- Err(format!("error executing, code {}", code.unwrap()).into())
- }
- else {
- Ok(())
- }
- },
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement