diff options
Diffstat (limited to 'src/parser/command.rs')
-rw-r--r-- | src/parser/command.rs | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/parser/command.rs b/src/parser/command.rs index 52b4666..5d129c3 100644 --- a/src/parser/command.rs +++ b/src/parser/command.rs @@ -3,14 +3,14 @@ use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus}; #[derive(Debug)] -pub enum Redirect { +pub(in crate::parser) enum Redirect { Std, FileOverwrite(String), FileAppend(String), } #[derive(Debug, PartialEq)] -pub enum RunOn { +pub(in crate::parser) enum RunOn { Always, ExitSuccess, ExitFailure, @@ -23,13 +23,13 @@ pub enum RunResult { #[derive(Debug)] pub struct CommandInfo { - pub args: Vec<String>, - pub stdout: Redirect, - pub when: RunOn, + pub(in crate::parser) args: Vec<String>, + pub(in crate::parser) stdout: Redirect, + pub(in crate::parser) when: RunOn, } impl CommandInfo { - pub fn new() -> CommandInfo { + pub(in crate::parser) fn new() -> CommandInfo { CommandInfo { args: Vec::new(), stdout: Redirect::Std, @@ -37,18 +37,13 @@ impl CommandInfo { } } - pub fn run( - &self, - home: &PathBuf, - cwd: &mut PathBuf, - status: &Option<ExitStatus>, - ) -> Result<RunResult, Error> { + pub fn run(&self, home: &PathBuf, status: &Option<ExitStatus>) -> Result<RunResult, Error> { match self.args[0].as_str() { "!" => { println!("{:?}", status); Ok(RunResult::Builtin) } - "cd" => cd(&self.args[1..], home, cwd), + "cd" => cd(&self.args[1..], home), "exit" => { std::process::exit(0); } @@ -62,7 +57,7 @@ impl CommandInfo { } } -fn cd(args: &[String], home: &PathBuf, cwd: &mut PathBuf) -> Result<RunResult, Error> { +fn cd(args: &[String], home: &PathBuf) -> Result<RunResult, Error> { if args.len() > 1 { return Err(Error::new( ErrorKind::InvalidInput, @@ -77,10 +72,7 @@ fn cd(args: &[String], home: &PathBuf, cwd: &mut PathBuf) -> Result<RunResult, E }; match std::env::set_current_dir(&root) { - Ok(_) => { - *cwd = root; - Ok(RunResult::Builtin) - } + Ok(_) => Ok(RunResult::Builtin), Err(e) => Err(e), } } |