aboutsummaryrefslogtreecommitdiff
path: root/src/builtins.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.rs')
-rw-r--r--src/builtins.rs21
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 {