Add confirmation dialoge when file already exists in download directory
This commit is contained in:
parent
c7415478a8
commit
0829590486
19
src/main.rs
19
src/main.rs
@ -121,8 +121,8 @@ enum OldVersionPolicy {
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! input {
|
macro_rules! input {
|
||||||
($prompt: expr) => {{
|
($prompt: tt) => {{
|
||||||
print!("{}", $prompt);
|
print!($prompt);
|
||||||
io::stdout().flush().expect("failed to flush stdout");
|
io::stdout().flush().expect("failed to flush stdout");
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
io::stdin()
|
io::stdin()
|
||||||
@ -352,7 +352,6 @@ fn main() -> Result<(), String> {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|entry| entry.file_name() == file_name)
|
.any(|entry| entry.file_name() == file_name)
|
||||||
{
|
{
|
||||||
//TODO ask user whether they want to override, unless silent flag is set
|
|
||||||
let duplication_notification = format!(
|
let duplication_notification = format!(
|
||||||
"A file with the name {} already exists in {}",
|
"A file with the name {} already exists in {}",
|
||||||
file_name.to_string_lossy(),
|
file_name.to_string_lossy(),
|
||||||
@ -360,14 +359,18 @@ fn main() -> Result<(), String> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if !args.quiet {
|
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!(
|
return Err(format!(
|
||||||
"A file with the name {} already exists in {}. You can override it with --override or -f",
|
"{duplication_notification}. You can override it with --override or -f"
|
||||||
file_name.to_string_lossy(),
|
));
|
||||||
working_directory.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user