From 0829590486c6e52c5516796e17ad673215cec5f8 Mon Sep 17 00:00:00 2001 From: Leonard Steppy Date: Wed, 15 Jan 2025 13:45:49 +0100 Subject: [PATCH] Add confirmation dialoge when file already exists in download directory --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2fd604a..07e7e80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,8 +121,8 @@ enum OldVersionPolicy { #[macro_export] macro_rules! input { - ($prompt: expr) => {{ - print!("{}", $prompt); + ($prompt: tt) => {{ + print!($prompt); io::stdout().flush().expect("failed to flush stdout"); let mut buf = String::new(); io::stdin() @@ -352,7 +352,6 @@ fn main() -> Result<(), String> { .iter() .any(|entry| entry.file_name() == file_name) { - //TODO ask user whether they want to override, unless silent flag is set let duplication_notification = format!( "A file with the name {} already exists in {}", file_name.to_string_lossy(), @@ -360,14 +359,18 @@ fn main() -> Result<(), String> { ); if !args.quiet { - print!("{duplication_notification}. Do you want to replace it? [N|y]"); + match input!("{duplication_notification}. Do you want to replace it? [N|y]") + .to_lowercase() + .as_str() + { + "y" | "yes" => break 'duplicate_check, + _ => {} + } } return Err(format!( - "A file with the name {} already exists in {}. You can override it with --override or -f", - file_name.to_string_lossy(), - working_directory.to_string_lossy() - )); + "{duplication_notification}. You can override it with --override or -f" + )); } }