Added git cmd docs
add delete and other cmd
This commit is contained in:
parent
4217c80a57
commit
b7eb893672
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -87,7 +87,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "breadpi-client"
|
name = "bp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "breadpi-client"
|
name = "bp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
52
src/git.rs
52
src/git.rs
@ -1,15 +1,30 @@
|
|||||||
use clap::Subcommand;
|
use clap::Subcommand;
|
||||||
use openssh::{Session, KnownHosts};
|
use openssh::{Session, KnownHosts};
|
||||||
|
use std::{process::Command, io};
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum GitCommand {
|
pub enum GitCommand {
|
||||||
Create {
|
/// Create a new repository in breadpi.
|
||||||
|
Init {
|
||||||
#[arg()]
|
#[arg()]
|
||||||
|
/// Name of the repo
|
||||||
name: String
|
name: String
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// List all repositories in breadpi.
|
||||||
List,
|
List,
|
||||||
|
|
||||||
|
/// Delete the specified repository in breadpi.
|
||||||
Delete {
|
Delete {
|
||||||
#[arg()]
|
#[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
|
name: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +35,7 @@ pub async fn handle_git(cmd: &GitCommand) {
|
|||||||
.expect("Could not connect to git@breadpi");
|
.expect("Could not connect to git@breadpi");
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
GitCommand::Create { name } => {
|
GitCommand::Init { name } => {
|
||||||
let init = session.command("git")
|
let init = session.command("git")
|
||||||
.arg("init")
|
.arg("init")
|
||||||
.arg("--bare")
|
.arg("--bare")
|
||||||
@ -31,10 +46,43 @@ pub async fn handle_git(cmd: &GitCommand) {
|
|||||||
"{}",
|
"{}",
|
||||||
String::from_utf8(init.stdout).expect("Failed to init git repo.")
|
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")
|
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");
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user