mirror of
https://github.com/sajenim/rush.git
synced 2025-06-28 01:44:21 +08:00
add some basic inbuilt commands
This commit is contained in:
parent
4eb0c39a66
commit
01b83996d1
2 changed files with 22 additions and 2 deletions
15
src/inbuilt.rs
Normal file
15
src/inbuilt.rs
Normal 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)
|
||||
}
|
||||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue