pub mod git; pub mod parser; use parser::*; use rustyline::error::ReadlineError; use std::{io, ops::ControlFlow}; use thiserror::Error; pub fn run_command(user_input: String) -> Result, ShackleError> { match user_input.parse::() { Err(parse_error) => { println!("{}", parse_error); } Ok(ShackleCommand::Whitespace) => {} Ok(ShackleCommand::Exit) => { return Ok(ControlFlow::Break(())); } Ok(ShackleCommand::GitInit(GitInitArgs { repo_name, group })) => { let init_result = git::init(&repo_name, &group)?; 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, #[error("Path is not accessible")] InvalidDirectory, #[error("`{0}`")] CustomError(String), }