Browse Source

prompt fn

db-refactoring
Coin de Gamma 3 months ago
parent
commit
a0da78c885
  1. 37
      src/main.rs

37
src/main.rs

@ -90,6 +90,25 @@ fn list() -> io:: Result<()> {
Ok(())
}
enum PROMPT {
YES,
NO
}
fn get_prompt(question: &str) -> io::Result<PROMPT> {
print!("{} [Y/n] ", question);
io::stdout().flush()?;
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let input = input.trim().to_lowercase();
match input.as_str() {
"y" => Ok(PROMPT::YES),
"n" => Ok(PROMPT::NO),
_ => Ok(PROMPT::YES),
}
}
fn main() -> io::Result<()> {
let cli = Cli::parse();
match &cli.command {
@ -104,23 +123,15 @@ fn main() -> io::Result<()> {
}
None => {
if !is_inited() {
print!("Do you want to init your storage? [Y/n] ");
io::stdout().flush().expect("Failed to flush stdout");
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read answer");
let input = input.trim().to_lowercase();
match input.as_str() {
"y" => init()?,
"n" => {
match get_prompt("Do you want to init your storage?")? {
PROMPT::YES => init()?,
PROMPT::NO => {
println!("mps can work only when storage inited.");
println!("Hint: you cant do");
println!(" git clone <your_storage_git_url> {}", STORAGE_FOLDER);
println!("to init manually your storage and config")
},
_ => init()?,
}
},
}
} else {
println!("login, not implemented yet")
}

Loading…
Cancel
Save