summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 93880de..0df2754 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,38 +1,45 @@
-use std::error::Error;
use std::{io, io::Write};
+use thiserror::Error;
-fn prompt() -> Result<(), Box<dyn Error>> {
+mod parser;
+
+use parser::Command;
+
+fn prompt() -> Result<(), ShackleError> {
print!("> ");
io::stdout().flush()?;
Ok(())
}
-fn read_stdin() -> Result<String, Box<dyn Error>> {
+fn read_stdin() -> Result<String, ShackleError> {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer)?;
Ok(buffer)
}
-fn main() -> Result<(), Box<dyn Error>> {
+fn main() -> Result<(), ShackleError> {
loop {
prompt()?;
let user_input = read_stdin()?;
- if user_input.len() == 0 {
- // control-d or end of input. Needs to be specially handled before
- // the match because this is identical to whitespace after the trim.
- break;
- }
-
- match user_input.trim() {
- "" => {}
- "exit" => {
+ match user_input.parse::<Command>() {
+ Err(unknown_input) => {
+ println!("Unknown input \"{}\"", unknown_input);
+ }
+ Ok(Command::Whitespace) => {}
+ Ok(Command::Exit) => {
break;
}
- other_input => {
- println!("Unknown input {}", other_input);
+ Ok(Command::GitInit(repo_name)) => {
+ println!("Successfully created {}.git", repo_name);
}
}
}
Ok(())
}
+
+#[derive(Error, Debug)]
+enum ShackleError {
+ #[error(transparent)]
+ IoError(#[from] io::Error),
+}