diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index f5b6f4cd7..bcefc39a6 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -15,7 +15,7 @@ use clap::{crate_version, error::ErrorKind, Arg, ArgAction, ArgMatches, Command} use std::env; use std::ffi::OsString; use std::fs; -use std::io::{self, stdin}; +use std::io; #[cfg(unix)] use std::os::unix; #[cfg(windows)] @@ -24,7 +24,7 @@ use std::path::{Path, PathBuf}; use uucore::backup_control::{self, BackupMode}; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError}; -use uucore::{format_usage, show, show_if_err}; +use uucore::{format_usage, prompt_yes, show, show_if_err}; use fs_extra::dir::{move_dir, CopyOptions as DirCopyOptions}; @@ -282,8 +282,7 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> { match b.overwrite { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { - println!("{}: overwrite {}? ", uucore::util_name(), target.quote()); - if !read_yes() { + if !prompt_yes!("overwrite {}? ", target.quote()) { return Ok(()); } } @@ -377,8 +376,7 @@ fn rename(from: &Path, to: &Path, b: &Behavior) -> io::Result<()> { match b.overwrite { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { - println!("{}: overwrite {}? ", uucore::util_name(), to.quote()); - if !read_yes() { + if !prompt_yes!("overwrite {}?", to.quote()) { return Ok(()); } } @@ -494,17 +492,6 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> { Ok(()) } -fn read_yes() -> bool { - let mut s = String::new(); - match stdin().read_line(&mut s) { - Ok(_) => match s.chars().next() { - Some(x) => x == 'y' || x == 'Y', - _ => false, - }, - _ => false, - } -} - fn is_empty_dir(path: &Path) -> bool { match fs::read_dir(path) { Ok(contents) => contents.peekable().peek().is_none(), diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 55ac7d68d..b4470ccea 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -166,7 +166,7 @@ fn test_mv_interactive() { .arg(file_b) .pipe_in("n") .succeeds() - .no_stderr(); + .no_stdout(); assert!(at.file_exists(file_a)); assert!(at.file_exists(file_b)); @@ -178,7 +178,7 @@ fn test_mv_interactive() { .arg(file_b) .pipe_in("Yesh") // spell-checker:disable-line .succeeds() - .no_stderr(); + .no_stdout(); assert!(!at.file_exists(file_a)); assert!(at.file_exists(file_b));