Added clone command, fixed copy-paste errors

This commit is contained in:
breadone 2024-07-28 13:30:30 +12:00
parent f10707e224
commit f158a1ab77
No known key found for this signature in database

View File

@ -26,6 +26,13 @@ pub enum GitCommand {
#[arg()] #[arg()]
/// Name of the repo /// Name of the repo
name: String name: String
},
/// Clone a repo from the remote
Clone {
#[arg()]
/// Name of the repo
name: String
} }
} }
@ -72,11 +79,13 @@ pub async fn handle_git(cmd: &GitCommand) {
eprintln!( eprintln!(
"{}", "{}",
String::from_utf8(ls.stdout).expect("Failed to rm repo.") String::from_utf8(ls.stdout).expect("Failed to list repos.")
); );
} }
GitCommand::Add { name } => { add_remote_to_repo(name.to_string()); } GitCommand::Add { name } => { add_remote_to_repo(name.to_string()); }
GitCommand::Clone { name } => { clone_repo(name.to_string()); }
} }
} }
@ -86,12 +95,27 @@ fn add_remote_to_repo(name: String) {
.arg("remote") .arg("remote")
.arg("add") .arg("add")
.arg("origin") .arg("origin")
.arg("git@breadpi.local:/home/git/store/".to_owned() + &name + ".git") .arg("git@breadpi:/home/git/store/".to_owned() + &name + ".git")
.output().expect("Could not add remote"); .output().expect("Could not add remote");
eprintln!( eprintln!(
"{}", "{}",
String::from_utf8(cmd.stdout).expect("Failed to rm git repo.") String::from_utf8(cmd.stdout).expect("Failed to add git remote.")
); );
println!("Added remote origin git@breadpi.local:/home/git/store/{name}.git"); println!("Added remote origin git@breadpi:/home/git/store/{name}.git");
}
fn clone_repo(name: String) {
let cmd = Command::new("git")
.arg("clone")
.arg("git@breadpi:/home/git/store/".to_owned() + &name + ".git")
.output().expect("Could not clone repo");
eprintln!(
"{}",
String::from_utf8(cmd.stdout).expect("Failed to clone repo.")
);
println!("Clone repo git@breadpi:/home/git/store/{name}.git to local folder.");
} }