Skip to content

Commit

Permalink
revert delete question
Browse files Browse the repository at this point in the history
+ remove deleted success message for brevity
  • Loading branch information
marcelohdez committed Dec 24, 2023
1 parent 9a9f6c5 commit c26bd43
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,25 @@ fn try_template(template: &str, editor: &str, delete: bool, data_dir: &Path) ->
.wait()
.expect("Could not launch editor!");

if delete || ask_y_n("Would you like to delete this project?")? {
fs::remove_dir_all(&tmp_dir)?;
println!("Deleted.")
} else {
if delete || ask_y_n("Would you like to keep this project?")? {
println!("Saved as {tmp_dir:?}.");
} else {
fs::remove_dir_all(&tmp_dir)?;
}

Ok(())
}

fn ask_y_n(question: &str) -> anyhow::Result<bool> {
println!("{question} (Y/n)");
println!("{question} (y/N)");

let mut input = String::new();
io::stdin().read_line(&mut input)?;

match input.to_lowercase().trim() {
"" => Ok(true), // default to yes if only enter is pressed
"y" => Ok(true),
"n" => Ok(false),
_ => ask_y_n(question),
"n" | "" => Ok(false), // default to no if no input
_ => ask_y_n(question), // redo if wrong input
}
}

Expand Down

0 comments on commit c26bd43

Please sign in to comment.