summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-03-20 23:18:41 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-03-20 23:18:41 +0200
commit2b827a0ab06fb715290a0450a3fff56d3e6f4ee6 (patch)
treeb5e24df3fa573afd07b55a2330e88cabe2394e3f /src/lib.rs
parentae4b23d95dc8792231c1e8212978be8305ee1964 (diff)
Put git repos into a user-specific dir
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..b645918
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,43 @@
+pub mod git;
+pub mod parser;
+pub mod user;
+
+use parser::*;
+use rustyline::error::ReadlineError;
+use std::{io, ops::ControlFlow};
+use thiserror::Error;
+
+pub fn run_command(user_input: String) -> Result<ControlFlow<(), ()>, ShackleError> {
+ match user_input.parse::<ShackleCommand>() {
+ Err(parse_error) => {
+ println!("{}", parse_error);
+ }
+ Ok(ShackleCommand::Whitespace) => {}
+ Ok(ShackleCommand::Exit) => {
+ return Ok(ControlFlow::Break(()));
+ }
+ Ok(ShackleCommand::GitInit(GitInitArgs { repo_name })) => {
+ let init_result = git::init(&repo_name)?;
+ println!("Successfully created \"{}\"", init_result.path.display());
+ }
+ Ok(ShackleCommand::GitUploadPack(upload_pack_args)) => {
+ git::upload_pack(&upload_pack_args)?;
+ }
+ Ok(ShackleCommand::GitReceivePack(receive_pack_args)) => {
+ git::receive_pack(&receive_pack_args)?;
+ }
+ }
+ Ok(ControlFlow::Continue(()))
+}
+
+#[derive(Error, Debug)]
+pub enum ShackleError {
+ #[error(transparent)]
+ IoError(#[from] io::Error),
+ #[error(transparent)]
+ GitError(#[from] git2::Error),
+ #[error(transparent)]
+ ReadlineError(#[from] ReadlineError),
+ #[error("Could not get the current user name")]
+ UserReadError,
+}