Browse Source

feat: exit directly when using exit command

main
fdai7451 2 years ago
parent
commit
357747ccf0
  1. 6
      src/builtins/exit.rs
  2. 2
      src/error.rs
  3. 3
      src/main.rs

6
src/builtins/exit.rs

@ -5,11 +5,11 @@ pub struct Exit;
impl Builtin for Exit {
fn execute(&mut self, _: Vec<String>) -> Result<(), ShellError> {
Err(ShellError::Exit)
std::process::exit(0)
}
}
#[cfg(test)]
/*#[cfg(test)]
mod tests {
use super::*;
@ -22,4 +22,4 @@ mod tests {
fn test_exit_without_args() {
assert_eq!(Exit.execute(vec![]), Err(ShellError::Exit))
}
}
}*/

2
src/error.rs

@ -3,7 +3,6 @@ use std::process::Command;
#[derive(Debug)]
pub enum ShellError {
EmptyLine,
Exit,
NotFound(Command),
ExecuteFailure(String),
MalformedArgs(String),
@ -13,7 +12,6 @@ impl PartialEq<Self> for ShellError {
fn eq(&self, other: &Self) -> bool {
match self {
&ShellError::EmptyLine => matches!(other, ShellError::EmptyLine),
&ShellError::Exit => matches!(other, ShellError::Exit),
&ShellError::NotFound(_) => matches!(other, ShellError::NotFound(_)),
&ShellError::ExecuteFailure(_) => matches!(other, ShellError::ExecuteFailure(_)),
&ShellError::MalformedArgs(_) => matches!(other, ShellError::MalformedArgs(_)),

3
src/main.rs

@ -25,9 +25,6 @@ fn main() -> Result<()> {
Err(ShellError::EmptyLine) => {
continue;
}
Err(ShellError::Exit) => {
break;
}
Err(ShellError::NotFound(cmd)) => {
eprintln!("{}: command not found", cmd.get_program().to_string_lossy())
}

Loading…
Cancel
Save