diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-10-14 22:31:57 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-10-14 22:31:57 +0300 |
commit | f8f482f6b08d3752a680abcb9cb3c58989888f63 (patch) | |
tree | 53709b0d93dee7cdede559f57789206e66041c38 /src/builtins.rs | |
parent | Check arguments passed to cd (diff) | |
download | rshell-f8f482f6b08d3752a680abcb9cb3c58989888f63.tar.xz |
Add ! builtin to display the last status
Diffstat (limited to 'src/builtins.rs')
-rw-r--r-- | src/builtins.rs | 21 |
1 files changed, 11 insertions, 10 deletions
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<std::path::PathBuf, std::string::String> { +pub fn cd(args: &[&str], home: &PathBuf) -> Result<PathBuf, Error> { 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<std::process::ExitStatus, Error> { + let mut child = Command::new(command).args(args).spawn()?; + child.wait() } /* match command { |