diff --git a/src/inbuilt.rs b/src/inbuilt.rs new file mode 100644 index 0000000..57d7b4a --- /dev/null +++ b/src/inbuilt.rs @@ -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) +} + diff --git a/src/main.rs b/src/main.rs index 60a9dd9..95d0ad1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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), + } } }