blob: ebbf23aae42a1543d8486d9a5c338e73139735f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
use std::{io, io::Write, process};
use thiserror::Error;
mod git;
mod parser;
use parser::Command;
fn prompt() -> Result<(), ShackleError> {
print!("> ");
io::stdout().flush()?;
Ok(())
}
fn read_stdin() -> Result<String, ShackleError> {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer)?;
Ok(buffer)
}
fn main() -> Result<(), ShackleError> {
loop {
prompt()?;
let user_input = read_stdin()?;
match user_input.parse::<Command>() {
Err(unknown_input) => {
println!("Unknown input \"{}\"", unknown_input);
}
Ok(Command::Whitespace) => {}
Ok(Command::Exit) => {
break;
}
Ok(Command::GitInit(repo_name)) => {
git::init(&repo_name)?; // TODO should report this error differently
println!("Successfully created {}.git", repo_name);
}
Ok(Command::GitUploadPack(git_dir)) => {
process::Command::new("git")
.args(["upload-pack", &git_dir])
.spawn()?
.wait()?;
}
Ok(Command::GitReceivePack(git_dir)) => {
process::Command::new("git")
.args(["receive-pack", &git_dir])
.spawn()?
.wait()?;
}
}
}
Ok(())
}
#[derive(Error, Debug)]
pub enum ShackleError {
#[error(transparent)]
IoError(#[from] io::Error),
#[error(transparent)]
GitError(#[from] git2::Error),
}
|