git cloning now working
This commit is contained in:
parent
a872e4681d
commit
ee83fa5e84
21
src/git.rs
21
src/git.rs
@ -1,5 +1,6 @@
|
||||
use clap::Subcommand;
|
||||
use openssh::{Session, KnownHosts};
|
||||
use inquire::{Select, InquireError};
|
||||
use core::str;
|
||||
use std::process::Command;
|
||||
|
||||
@ -121,16 +122,26 @@ async fn list_repos(session: &Session) -> Vec<String> {
|
||||
}
|
||||
|
||||
async fn clone_repo(name: &Option<String>, session: &Session) {
|
||||
let mut unwrapped_name: String = "".to_string();
|
||||
|
||||
// check if name is null and present list if so
|
||||
if name.is_none() {
|
||||
// let list = list_repos(session).await;
|
||||
}
|
||||
let list = list_repos(session).await;
|
||||
let repos = list.iter().map(|s| s as &str).collect();
|
||||
|
||||
let unwrapped_name = "&name.unwrap()";
|
||||
let repo: Result<&str, InquireError> = Select::new("Choose a repo: ", repos).prompt();
|
||||
|
||||
match repo {
|
||||
Ok(s) => unwrapped_name = s.to_string(),
|
||||
Err(_) => println!("error!")
|
||||
}
|
||||
} else {
|
||||
unwrapped_name = name.clone().unwrap() + ".git";
|
||||
}
|
||||
|
||||
let cmd = Command::new("git")
|
||||
.arg("clone")
|
||||
.arg("git@breadpi:/home/git/store/".to_owned() + &unwrapped_name + ".git")
|
||||
.arg("git@breadpi:/home/git/store/".to_owned() + &unwrapped_name)
|
||||
.output().expect("Could not clone repo");
|
||||
|
||||
eprintln!(
|
||||
@ -138,5 +149,5 @@ async fn clone_repo(name: &Option<String>, session: &Session) {
|
||||
String::from_utf8(cmd.stdout).expect("Failed to clone repo.")
|
||||
);
|
||||
|
||||
println!("Cloned repo git@breadpi:/home/git/store/{unwrapped_name}.git to {unwrapped_name}.");
|
||||
println!("Cloned repo git@breadpi:/home/git/store/{unwrapped_name} to {unwrapped_name}.");
|
||||
}
|
@ -4,6 +4,8 @@ use tokio;
|
||||
use clap::{Parser, Subcommand};
|
||||
use crate::git::{handle_git, GitCommand};
|
||||
|
||||
const VERSION: &str = "2.0b1";
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
/// Various commands for creating and adding git repos to breadpi.
|
||||
@ -22,9 +24,9 @@ struct Cli {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args = Cli::parse();
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &args.command {
|
||||
match &cli.command {
|
||||
Command::Git { git_command } => {
|
||||
handle_git(&git_command).await;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user