From 7bb0e8f8492fedafcf378c25a22ddbd95100fd8b Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Wed, 16 Nov 2022 15:15:42 +0100 Subject: [PATCH] ln: use uucore::prompt_yes over custom function --- src/uu/ln/src/ln.rs | 17 ++--------------- tests/by-util/test_ln.rs | 4 ++-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 65b5f88dd..d9d20686e 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -11,7 +11,7 @@ use clap::{crate_version, Arg, ArgAction, Command}; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; use uucore::fs::{make_path_relative_to, paths_refer_to_same_file}; -use uucore::{format_usage, show_error}; +use uucore::{format_usage, prompt_yes, show_error}; use std::borrow::Cow; use std::error::Error; @@ -19,7 +19,6 @@ use std::ffi::OsString; use std::fmt::Display; use std::fs; -use std::io::stdin; #[cfg(any(unix, target_os = "redox"))] use std::os::unix::fs::symlink; #[cfg(windows)] @@ -410,8 +409,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> { match settings.overwrite { OverwriteMode::NoClobber => {} OverwriteMode::Interactive => { - print!("{}: overwrite {}? ", uucore::util_name(), dst.quote()); - if !read_yes() { + if !prompt_yes!("overwrite {}?", dst.quote()) { return Ok(()); } @@ -459,17 +457,6 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> { Ok(()) } -fn read_yes() -> bool { - let mut s = String::new(); - match stdin().read_line(&mut s) { - Ok(_) => match s.char_indices().next() { - Some((_, x)) => x == 'y' || x == 'Y', - _ => false, - }, - _ => false, - } -} - fn simple_backup_path(path: &Path, suffix: &str) -> PathBuf { let mut p = path.as_os_str().to_str().unwrap().to_owned(); p.push_str(suffix); diff --git a/tests/by-util/test_ln.rs b/tests/by-util/test_ln.rs index cb4729adf..07b824649 100644 --- a/tests/by-util/test_ln.rs +++ b/tests/by-util/test_ln.rs @@ -117,7 +117,7 @@ fn test_symlink_interactive() { .args(&["-i", "-s", file, link]) .pipe_in("n") .succeeds() - .no_stderr(); + .no_stdout(); assert!(at.file_exists(file)); assert!(!at.is_symlink(link)); @@ -127,7 +127,7 @@ fn test_symlink_interactive() { .args(&["-i", "-s", file, link]) .pipe_in("Yesh") // spell-checker:disable-line .succeeds() - .no_stderr(); + .no_stdout(); assert!(at.file_exists(file)); assert!(at.is_symlink(link));