feat: tie dialog to graph

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-09 14:10:43 +02:00
parent 7cead58ed3
commit 547d34782c
5 changed files with 143 additions and 6 deletions

View File

@@ -0,0 +1,37 @@
use itertools::Itertools;
pub enum Commands {
Write,
Quit,
WriteQuit,
}
impl Commands {
pub fn is_write(&self) -> bool {
matches!(self, Commands::Write | Commands::WriteQuit)
}
pub fn is_quit(&self) -> bool {
matches!(self, Commands::Quit | Commands::WriteQuit)
}
}
pub struct CommandParser {}
impl CommandParser {
pub fn parse(raw_command: &str) -> Option<Commands> {
let prepared = raw_command.trim();
// TODO: respect quotes
let parts = prepared.split_whitespace().collect_vec();
match parts.split_first() {
Some((command, _)) => match *command {
"w" | "write" => Some(Commands::Write),
"q" | "quit" => Some(Commands::Quit),
"wq" | "write-quit" => Some(Commands::WriteQuit),
_ => None,
},
None => None,
}
}
}