Skip to content

Commit e977cfd

Browse files
committed
Feat: Add bang syntax in chat, remove context modifiers, and add help command
1 parent e406066 commit e977cfd

File tree

7 files changed

+239
-521
lines changed

7 files changed

+239
-521
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use eyre::Result;
2+
3+
pub enum Command {
4+
Ask { prompt: String },
5+
Execute { command: String },
6+
Clear,
7+
Help,
8+
Quit,
9+
}
10+
11+
impl Command {
12+
pub fn parse(input: &str) -> Result<Self, String> {
13+
let input = input.trim();
14+
15+
if let Some(command) = input.strip_prefix("/") {
16+
return Ok(match command.to_lowercase().as_str() {
17+
"clear" => Self::Clear,
18+
"help" => Self::Help,
19+
"q" | "exit" | "quit" => Self::Quit,
20+
_ => return Err(format!("Unknown command: {}", input)),
21+
});
22+
}
23+
24+
if let Some(command) = input.strip_prefix("!") {
25+
return Ok(Self::Execute {
26+
command: command.to_string(),
27+
});
28+
}
29+
30+
Ok(Self::Ask {
31+
prompt: input.to_string(),
32+
})
33+
}
34+
}

0 commit comments

Comments
 (0)