From f8f482f6b08d3752a680abcb9cb3c58989888f63 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 14 Oct 2020 22:31:57 +0300 Subject: Add ! builtin to display the last status --- src/builtins.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/builtins.rs') diff --git a/src/builtins.rs b/src/builtins.rs index ac83efa..bcc14f1 100644 --- a/src/builtins.rs +++ b/src/builtins.rs @@ -1,12 +1,13 @@ -use std::path::Path; +use std::io::{Error, ErrorKind}; +use std::path::{Path, PathBuf}; use std::process::Command; -pub fn cd( - args: &[&str], - home: &std::path::PathBuf, -) -> Result { +pub fn cd(args: &[&str], home: &PathBuf) -> Result { if args.len() > 1 { - return Err("Too many arguments passed to cd".to_string()); + return Err(Error::new( + ErrorKind::InvalidInput, + "Too many arguments passed to cd", + )); } if args.len() == 0 { @@ -20,13 +21,13 @@ pub fn cd( match std::env::set_current_dir(&root) { Ok(_) => Ok(root.to_path_buf()), - Err(e) => Err(format!("Could not set current dir: {}", e)), + Err(e) => Err(e), } } -pub fn run(command: &str, args: &[&str]) { - let mut child = Command::new(command).args(args).spawn().unwrap(); - child.wait().unwrap(); +pub fn run(command: &str, args: &[&str]) -> Result { + let mut child = Command::new(command).args(args).spawn()?; + child.wait() } /* match command { -- cgit v1.2.1