From ee83fa5e8408b3522379f16bfb721dd614f64467 Mon Sep 17 00:00:00 2001 From: breadone Date: Sun, 28 Jul 2024 17:31:27 +1200 Subject: [PATCH] git cloning now working --- src/git.rs | 21 ++++++++++++++++----- src/main.rs | 6 ++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/git.rs b/src/git.rs index da0cd3e..366b0b8 100644 --- a/src/git.rs +++ b/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 { } async fn clone_repo(name: &Option, 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, 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}."); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4ee3045..6608b6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; }