fdai7451
2 years ago
7 changed files with 86 additions and 16 deletions
-
17src/builtins/cd.rs
-
30src/builtins/change_prompt.rs
-
4src/builtins/exit.rs
-
34src/builtins/mod.rs
-
10src/execute.rs
-
6src/main.rs
-
1src/prompt.rs
@ -0,0 +1,30 @@ |
|||||
|
use crate::builtins::{Builtin, BuiltinConfig};
|
||||
|
use crate::error::ShellError;
|
||||
|
use crate::prompt::PromptStyle;
|
||||
|
|
||||
|
pub struct ChangePrompt;
|
||||
|
|
||||
|
impl Builtin for ChangePrompt {
|
||||
|
fn execute(&mut self, config: &mut BuiltinConfig, args: Vec<String>) -> Result<(), ShellError> {
|
||||
|
if args.len() > 1 {
|
||||
|
Err(ShellError::ExecuteFailure(
|
||||
|
"expected only one argument".to_string(),
|
||||
|
))
|
||||
|
} else if let Some(style) = args.get(0) {
|
||||
|
match style.to_lowercase().as_str() {
|
||||
|
"none" => config.prompt_style = PromptStyle::None,
|
||||
|
_ => {
|
||||
|
return Err(ShellError::ExecuteFailure(format!(
|
||||
|
"{} is not a valid prompt style",
|
||||
|
style
|
||||
|
)))
|
||||
|
}
|
||||
|
}
|
||||
|
Ok(())
|
||||
|
} else {
|
||||
|
Err(ShellError::ExecuteFailure(
|
||||
|
"expected at least one argument".to_string(),
|
||||
|
))
|
||||
|
}
|
||||
|
}
|
||||
|
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue