1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

ln: use uucore::prompt_yes over custom function

This commit is contained in:
Terts Diepraam 2022-11-16 15:15:42 +01:00
parent ed34264b95
commit 7bb0e8f849
2 changed files with 4 additions and 17 deletions

View file

@ -11,7 +11,7 @@ use clap::{crate_version, Arg, ArgAction, Command};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult}; use uucore::error::{FromIo, UError, UResult};
use uucore::fs::{make_path_relative_to, paths_refer_to_same_file}; 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::borrow::Cow;
use std::error::Error; use std::error::Error;
@ -19,7 +19,6 @@ use std::ffi::OsString;
use std::fmt::Display; use std::fmt::Display;
use std::fs; use std::fs;
use std::io::stdin;
#[cfg(any(unix, target_os = "redox"))] #[cfg(any(unix, target_os = "redox"))]
use std::os::unix::fs::symlink; use std::os::unix::fs::symlink;
#[cfg(windows)] #[cfg(windows)]
@ -410,8 +409,7 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
match settings.overwrite { match settings.overwrite {
OverwriteMode::NoClobber => {} OverwriteMode::NoClobber => {}
OverwriteMode::Interactive => { OverwriteMode::Interactive => {
print!("{}: overwrite {}? ", uucore::util_name(), dst.quote()); if !prompt_yes!("overwrite {}?", dst.quote()) {
if !read_yes() {
return Ok(()); return Ok(());
} }
@ -459,17 +457,6 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
Ok(()) 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 { fn simple_backup_path(path: &Path, suffix: &str) -> PathBuf {
let mut p = path.as_os_str().to_str().unwrap().to_owned(); let mut p = path.as_os_str().to_str().unwrap().to_owned();
p.push_str(suffix); p.push_str(suffix);

View file

@ -117,7 +117,7 @@ fn test_symlink_interactive() {
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.pipe_in("n") .pipe_in("n")
.succeeds() .succeeds()
.no_stderr(); .no_stdout();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(!at.is_symlink(link)); assert!(!at.is_symlink(link));
@ -127,7 +127,7 @@ fn test_symlink_interactive() {
.args(&["-i", "-s", file, link]) .args(&["-i", "-s", file, link])
.pipe_in("Yesh") // spell-checker:disable-line .pipe_in("Yesh") // spell-checker:disable-line
.succeeds() .succeeds()
.no_stderr(); .no_stdout();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));