generated from pure_sagacity/rust-starter
378c1f7c0d
cursor.
62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use clap::Parser;
|
|
use dialoguer::{Select, theme::ColorfulTheme};
|
|
use std::io::Write;
|
|
use std::io;
|
|
|
|
mod cli;
|
|
mod config;
|
|
mod credentials;
|
|
mod providers;
|
|
mod tui;
|
|
|
|
pub(crate) const CONFIG_PATH: &str = "~/.config/clonee";
|
|
|
|
pub(crate) enum DefaultAnswer {
|
|
Yes,
|
|
No,
|
|
}
|
|
|
|
pub(crate) fn ask_option<T>(message: &str, options: Vec<T>) -> T
|
|
where
|
|
T: std::fmt::Display + Clone,
|
|
{
|
|
let selection = Select::with_theme(&ColorfulTheme::default())
|
|
.with_prompt(message.to_string())
|
|
.items(&options)
|
|
.default(0)
|
|
.interact()
|
|
.unwrap();
|
|
|
|
options[selection].clone()
|
|
}
|
|
|
|
pub(crate) fn ask_yes_no(message: &str, default: Option<DefaultAnswer>) -> bool {
|
|
let options: Vec<&str> = match default {
|
|
Some(DefaultAnswer::Yes) => vec!["Yes", "No"],
|
|
Some(DefaultAnswer::No) => vec!["No", "Yes"],
|
|
None => vec!["Yes", "No"],
|
|
};
|
|
|
|
match ask_option(message, options) {
|
|
"Yes" => true,
|
|
"No" => false,
|
|
_ => unreachable!(),
|
|
}
|
|
}
|
|
|
|
pub(crate) 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]
|
|
async fn main() {
|
|
let cli = cli::Cli::parse();
|
|
cli::run(cli).await;
|
|
}
|