From a1cf262414415859685c1b11762afc7065df8a64 Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Tue, 26 Dec 2017 15:25:03 -0800 Subject: [PATCH] rm: exit normally when -f is used with no operand --- src/rm/rm.rs | 7 +++++-- tests/test_rm.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rm/rm.rs b/src/rm/rm.rs index 8679848c2..b4072b790 100644 --- a/src/rm/rm.rs +++ b/src/rm/rm.rs @@ -66,6 +66,9 @@ pub fn uumain(args: Vec) -> i32 { Ok(m) => m, Err(f) => crash!(1, "{}", f) }; + + let force = matches.opt_present("force"); + if matches.opt_present("help") { println!("{} {}", NAME, VERSION); println!(""); @@ -87,13 +90,13 @@ pub fn uumain(args: Vec) -> i32 { println!("assurance that the contents are truly unrecoverable, consider using shred."); } else if matches.opt_present("version") { println!("{} {}", NAME, VERSION); - } else if matches.free.is_empty() { + } else if matches.free.is_empty() && !force { show_error!("missing an argument"); show_error!("for help, try '{0} --help'", NAME); return 1; } else { let options = Options { - force: matches.opt_present("force"), + force: force, interactive: { if matches.opt_present("i") { InteractiveMode::InteractiveAlways diff --git a/tests/test_rm.rs b/tests/test_rm.rs index 9f7f46b56..6d8ea2d0a 100644 --- a/tests/test_rm.rs +++ b/tests/test_rm.rs @@ -158,3 +158,18 @@ fn test_rm_invalid_symlink() { 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"); +}