Browse Source

feat: add cd builtin command

main
fdai7375 2 years ago
parent
commit
f5812d5e88
  1. 8
      src/builtins/cd.rs
  2. 7
      src/builtins/mod.rs

8
src/builtins/cd.rs

@ -0,0 +1,8 @@
use std::env::set_current_dir;
use crate::error::ShellError;
pub fn run(keyword: &str, args: &[&str]) -> Result<(), ShellError> {
set_current_dir(args[0]);
Ok(())
}

7
src/builtins/mod.rs

@ -1,11 +1,16 @@
use crate::error::ShellError; use crate::error::ShellError;
mod cd;
const BUILTINS: &[&str] = &[];
const BUILTINS: &[&str] = &["cd"];
pub fn is_builtin(keyword: &str) -> bool { pub fn is_builtin(keyword: &str) -> bool {
BUILTINS.contains(&keyword) BUILTINS.contains(&keyword)
} }
pub fn execute_builtin(keyword: &str, args: &[&str]) -> Result<(), ShellError> { pub fn execute_builtin(keyword: &str, args: &[&str]) -> Result<(), ShellError> {
match keyword {
"cd" => cd::run(keyword, args)?,
_ => {}
}
Ok(()) Ok(())
} }
Loading…
Cancel
Save