add some basic inbuilt commands

This commit is contained in:
♥ Minnie ♥ 2025-06-07 15:05:59 +08:00
parent 4eb0c39a66
commit 01b83996d1
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
2 changed files with 22 additions and 2 deletions

15
src/inbuilt.rs Normal file
View file

@ -0,0 +1,15 @@
use std::env;
pub fn cd(args: Vec<&str>) {
let path = args[0].to_string();
assert!(env::set_current_dir(&path).is_ok());
}
pub fn help() {
println!("This is an example help message")
}
pub fn exit() {
std::process::exit(0x0100)
}

View file

@ -21,7 +21,12 @@ fn main() {
let cmd = core::get_command(tokens.clone());
let args = core::get_args(tokens);
// Execute command and argument.
core::execute(cmd, args);
// Execute inbuilt commands if supplied, otherwise execute command and argument.
match cmd {
"cd" => inbuilt::cd(args),
"help" => inbuilt::help(),
"exit" => inbuilt::exit(),
_ => core::execute(cmd, args),
}
}
}