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

Merge pull request #1116 from Arcterus/rm_f_fix

rm: exit normally when -f is used with no operand
This commit is contained in:
mpkh 2017-12-27 10:34:14 +04:00 committed by GitHub
commit c386d5bfaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,
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<String>) -> 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

View file

@ -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");
}