Browse Source

feat: add exit builtin command

main
fdai7381 2 years ago
parent
commit
23e6cfd4b0
  1. 5
      src/builtins/exit.rs
  2. 4
      src/builtins/mod.rs

5
src/builtins/exit.rs

@ -0,0 +1,5 @@
use crate::error::ShellError;
pub fn run() -> Result<(), ShellError> {
Err(ShellError::Exit)
}

4
src/builtins/mod.rs

@ -1,7 +1,8 @@
use crate::error::ShellError;
mod cd;
mod exit;
const BUILTINS: &[&str] = &["cd"];
const BUILTINS: &[&str] = &["exit", "cd"];
pub fn is_builtin(keyword: &str) -> bool {
BUILTINS.contains(&keyword)
@ -9,6 +10,7 @@ pub fn is_builtin(keyword: &str) -> bool {
pub fn execute_builtin(keyword: &str, args: &[&str]) -> Result<(), ShellError> {
match keyword {
"exit" => exit::run()?,
"cd" => cd::run(args)?,
_ => {}
}

Loading…
Cancel
Save