diff --git a/Cargo.lock b/Cargo.lock index 4380f8b..c9c1714 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,7 +87,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] -name = "breadpi-client" +name = "bp" version = "0.1.0" dependencies = [ "clap", diff --git a/Cargo.toml b/Cargo.toml index d70b6f0..f61bc67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "breadpi-client" +name = "bp" version = "0.1.0" edition = "2021" diff --git a/src/git.rs b/src/git.rs index 2712067..65549d5 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,15 +1,30 @@ use clap::Subcommand; use openssh::{Session, KnownHosts}; +use std::{process::Command, io}; #[derive(Subcommand)] pub enum GitCommand { - Create { + /// Create a new repository in breadpi. + Init { #[arg()] + /// Name of the repo name: String }, + + /// List all repositories in breadpi. List, + + /// Delete the specified repository in breadpi. Delete { #[arg()] + /// Name of the repo + name: String + }, + + /// Add remote to the git repo in the current directory + Add { + #[arg()] + /// Name of the repo name: String } } @@ -20,7 +35,7 @@ pub async fn handle_git(cmd: &GitCommand) { .expect("Could not connect to git@breadpi"); match cmd { - GitCommand::Create { name } => { + GitCommand::Init { name } => { let init = session.command("git") .arg("init") .arg("--bare") @@ -31,10 +46,43 @@ pub async fn handle_git(cmd: &GitCommand) { "{}", String::from_utf8(init.stdout).expect("Failed to init git repo.") ); + + print!("Would you like to add the remote to the repo in this directory? (Y/n): "); } + GitCommand::Delete { name } => { + let rm = session.command("rm") + .arg("-r") + .arg("-f") + .arg("store/".to_owned() + name + ".git") + .output().await.unwrap(); + + eprintln!( + "{}", + String::from_utf8(rm.stdout).expect("Failed to rm repo.") + ); + } + + GitCommand::Add { name } => { add_remote_to_repo(name.to_string()); } + _ => { println!("oopsies") } } +} + + +fn add_remote_to_repo(name: String) { + let cmd = Command::new("git") + .arg("remote") + .arg("add") + .arg("origin") + .arg("git@breadpi.local:/home/git/store/".to_owned() + &name + ".git") + .output().expect("Could not add remote"); + eprintln!( + "{}", + String::from_utf8(cmd.stdout).expect("Failed to rm git repo.") + ); + + println!("Added remote origin git@breadpi.local:/home/git/store/{name}.git"); } \ No newline at end of file