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

rm: exit normally when -f is used with no operand

This commit is contained in:
Alex Lyon 2017-12-26 15:25:03 -08:00
parent be5ce3c252
commit a1cf262414
2 changed files with 20 additions and 2 deletions

View file

@ -66,6 +66,9 @@ pub fn uumain(args: Vec<String>) -> i32 {
Ok(m) => m, Ok(m) => m,
Err(f) => crash!(1, "{}", f) Err(f) => crash!(1, "{}", f)
}; };
let force = matches.opt_present("force");
if matches.opt_present("help") { if matches.opt_present("help") {
println!("{} {}", NAME, VERSION); println!("{} {}", NAME, VERSION);
println!(""); println!("");
@ -87,13 +90,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
println!("assurance that the contents are truly unrecoverable, consider using shred."); println!("assurance that the contents are truly unrecoverable, consider using shred.");
} else if matches.opt_present("version") { } else if matches.opt_present("version") {
println!("{} {}", NAME, VERSION); println!("{} {}", NAME, VERSION);
} else if matches.free.is_empty() { } else if matches.free.is_empty() && !force {
show_error!("missing an argument"); show_error!("missing an argument");
show_error!("for help, try '{0} --help'", NAME); show_error!("for help, try '{0} --help'", NAME);
return 1; return 1;
} else { } else {
let options = Options { let options = Options {
force: matches.opt_present("force"), force: force,
interactive: { interactive: {
if matches.opt_present("i") { if matches.opt_present("i") {
InteractiveMode::InteractiveAlways InteractiveMode::InteractiveAlways

View file

@ -158,3 +158,18 @@ fn test_rm_invalid_symlink() {
ucmd.arg(link).succeeds(); ucmd.arg(link).succeeds();
} }
#[test]
fn test_rm_force_no_operand() {
let mut ucmd = new_ucmd!();
ucmd.arg("-f").succeeds().no_stderr();
}
#[test]
fn test_rm_no_operand() {
let mut ucmd = new_ucmd!();
ucmd.fails()
.stderr_is("rm: error: missing an argument\nrm: error: for help, try 'rm --help'\n");
}