From 23e6cfd4b0814b8018726013ae8ee3c436a49235 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Thu, 19 Jan 2023 01:34:52 +0100 Subject: [PATCH] feat: add exit builtin command --- src/builtins/exit.rs | 5 +++++ src/builtins/mod.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/builtins/exit.rs diff --git a/src/builtins/exit.rs b/src/builtins/exit.rs new file mode 100644 index 0000000..dd56735 --- /dev/null +++ b/src/builtins/exit.rs @@ -0,0 +1,5 @@ +use crate::error::ShellError; + +pub fn run() -> Result<(), ShellError> { + Err(ShellError::Exit) +} \ No newline at end of file diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index f324863..56adceb 100644 --- a/src/builtins/mod.rs +++ b/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)?, _ => {} }