diff --git a/src/uu/rm/locales/en-US.ftl b/src/uu/rm/locales/en-US.ftl index 38511105394..6affece404d 100644 --- a/src/uu/rm/locales/en-US.ftl +++ b/src/uu/rm/locales/en-US.ftl @@ -50,6 +50,7 @@ rm-error-and-preserve-root-all-in-effect = and --preserve-root=all is in effect rm-error-cannot-remove = cannot remove {$file} rm-error-cannot-remove-changed = cannot remove {$file}: File changed while removing rm-error-may-not-abbreviate-no-preserve-root = you may not abbreviate the --no-preserve-root option +rm-error-unrecognized-preserve-root-argument = unrecognized --preserve-root argument: '{$arg}' rm-error-standard-output = standard output: {$error} # Verbose messages diff --git a/src/uu/rm/locales/fr-FR.ftl b/src/uu/rm/locales/fr-FR.ftl index fdbf1275fec..090f210cc01 100644 --- a/src/uu/rm/locales/fr-FR.ftl +++ b/src/uu/rm/locales/fr-FR.ftl @@ -48,6 +48,7 @@ rm-error-refusing-to-remove-directory = refus de supprimer le répertoire '.' ou rm-error-cannot-remove = impossible de supprimer {$file} rm-error-cannot-remove-changed = impossible de supprimer {$file} : Le fichier a changé pendant la suppression rm-error-may-not-abbreviate-no-preserve-root = Vous ne pouvez pas abréger l'option --no-preserve-root +rm-error-unrecognized-preserve-root-argument = argument --preserve-root non reconnu : '{$arg}' rm-error-standard-output = sortie standard : {$error} # Messages verbeux diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index f1436b4bd13..b5c64d5dfac 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -264,9 +264,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; let preserve_root = !matches.get_flag(OPT_NO_PRESERVE_ROOT); - let preserve_root_all = matches - .get_one::(OPT_PRESERVE_ROOT) - .is_some_and(|value| value == "all"); + let preserve_root_all = match matches.get_one::(OPT_PRESERVE_ROOT) { + Some(value) if value == "all" => true, + Some(value) => { + return Err(USimpleError::new( + 1, + translate!("rm-error-unrecognized-preserve-root-argument", "arg" => value.clone()), + )); + } + None => false, + }; let recursive = matches.get_flag(OPT_RECURSIVE); let options = Options { @@ -428,8 +435,7 @@ pub fn uu_app() -> Command { // additionally refuses to cross into another file system. .num_args(0..=1) .require_equals(true) - .value_name("all") - .value_parser(["all"]), + .value_name("all"), ) .arg( Arg::new(OPT_RECURSIVE) diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index c315d4112d5..2f96e7467a7 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -249,7 +249,19 @@ fn test_preserve_root_rejects_unknown_value() { .arg("-rf") .arg("anything") .fails() - .stderr_contains("invalid value 'bogus'"); + .stderr_is("rm: unrecognized --preserve-root argument: 'bogus'\n"); +} + +#[test] +fn test_preserve_root_rejects_abbreviation() { + // Unlike --interactive and friends, --preserve-root does not accept + // abbreviations of its one value at all: GNU rejects even 'a'. + new_ucmd!() + .arg("--preserve-root=a") + .arg("-rf") + .arg("anything") + .fails() + .stderr_is("rm: unrecognized --preserve-root argument: 'a'\n"); } #[test]