Browse Source

feat: add builtins module

main
fdai7375 2 years ago
parent
commit
2ae1471632
  1. 11
      src/builtins/mod.rs
  2. 11
      src/execute.rs
  3. 1
      src/main.rs

11
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(())
}

11
src/execute.rs

@ -1,6 +1,7 @@
use std::io::ErrorKind::NotFound; use std::io::ErrorKind::NotFound;
use std::process::Command; use std::process::Command;
use crate::builtins::{execute_builtin, is_builtin};
use crate::error::ShellError; use crate::error::ShellError;
use crate::parse::parse_line; use crate::parse::parse_line;
@ -10,10 +11,14 @@ pub fn interpret(line: &str) -> Result<(), ShellError> {
} }
let (keyword, args) = parse_line(line); 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(()) Ok(())
} }

1
src/main.rs

@ -1,3 +1,4 @@
mod builtins;
mod error; mod error;
mod execute; mod execute;
mod parse; mod parse;

Loading…
Cancel
Save