generated from pure_sagacity/rust-starter
finished the actual cloning logic.
This commit is contained in:
+44
-6
@@ -1,16 +1,25 @@
|
|||||||
use std::process;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
providers::{Provider, github::Github},
|
providers::{Provider, github::Github},
|
||||||
tui::user_select_repo,
|
tui::user_select_repo,
|
||||||
};
|
};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use dialoguer::{Select, theme::ColorfulTheme};
|
use dialoguer::{Select, theme::ColorfulTheme};
|
||||||
|
use std::io::Write;
|
||||||
|
use std::{io, process};
|
||||||
mod providers;
|
mod providers;
|
||||||
mod tui;
|
mod tui;
|
||||||
|
|
||||||
pub fn ask_yes_no(message: &str) -> bool {
|
enum DefaultAnswer {
|
||||||
let options = vec!["Yes", "No"];
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ask_yes_no(message: &str, default: Option<DefaultAnswer>) -> bool {
|
||||||
|
let options = match default {
|
||||||
|
Some(DefaultAnswer::Yes) => vec!["Yes", "No"],
|
||||||
|
Some(DefaultAnswer::No) => vec!["No", "Yes"],
|
||||||
|
None => vec!["Yes", "No"],
|
||||||
|
};
|
||||||
|
|
||||||
let selection = Select::with_theme(&ColorfulTheme::default())
|
let selection = Select::with_theme(&ColorfulTheme::default())
|
||||||
.with_prompt(message.to_string())
|
.with_prompt(message.to_string())
|
||||||
@@ -26,6 +35,16 @@ pub fn ask_yes_no(message: &str) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_input(message: &str) -> String {
|
||||||
|
print!("{}", message);
|
||||||
|
io::stdout().flush().unwrap();
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
io::stdin().read_line(&mut input).unwrap();
|
||||||
|
|
||||||
|
input.trim().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Testing to see if github provider works.
|
// Testing to see if github provider works.
|
||||||
@@ -43,7 +62,26 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{:#?}", selection);
|
match ask_yes_no("Clone the repo?", None) {
|
||||||
|
true => {
|
||||||
|
let folder: Option<String> =
|
||||||
|
if ask_yes_no("Use a custom folder?", Some(DefaultAnswer::No)) {
|
||||||
|
let custom = get_input("Folder name: ");
|
||||||
|
Some(custom)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
println!("{}", ask_yes_no("Clone the repo?"));
|
match gh.clone(selection, folder, false).await {
|
||||||
|
Ok(_) => println!("Repo cloned!"),
|
||||||
|
Err(_) => {
|
||||||
|
println!("{}", "Error cloning repo.".red())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
println!("Exiting...");
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user