From 2ae1471632b0cbd3f572a314e80ebaf4bd6c9cb7 Mon Sep 17 00:00:00 2001 From: fdai7375 Date: Thu, 19 Jan 2023 00:50:58 +0100 Subject: [PATCH] feat: add builtins module --- src/builtins/mod.rs | 11 +++++++++++ src/execute.rs | 11 ++++++++--- src/main.rs | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 src/builtins/mod.rs diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs new file mode 100644 index 0000000..cd4a7d1 --- /dev/null +++ b/src/builtins/mod.rs @@ -0,0 +1,11 @@ +use crate::error::ShellError; + +const BUILTINS: &[&str] = &[]; + +pub fn is_builtin(keyword: &str) -> bool { + BUILTINS.contains(&keyword) +} + +pub fn execute_builtin(keyword: &str, args: &[&str]) -> Result<(), ShellError> { + Ok(()) +} diff --git a/src/execute.rs b/src/execute.rs index 3a54865..8cc28bf 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -1,6 +1,7 @@ use std::io::ErrorKind::NotFound; use std::process::Command; +use crate::builtins::{execute_builtin, is_builtin}; use crate::error::ShellError; use crate::parse::parse_line; @@ -10,10 +11,14 @@ pub fn interpret(line: &str) -> Result<(), ShellError> { } let (keyword, args) = parse_line(line); - let mut command = Command::new(keyword); - command.args(args); + if is_builtin(keyword) { + execute_builtin(keyword, &args)?; + } else { + let mut command = Command::new(keyword); + command.args(args); - execute(command)?; + execute(command)?; + } Ok(()) } diff --git a/src/main.rs b/src/main.rs index 237c641..c19774c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod builtins; mod error; mod execute; mod parse;