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

Merge pull request #8045 from cakebaker/rm_earlier_early_return

rm: do "early return" earlier in `uumain`
This commit is contained in:
Sylvestre Ledru 2025-06-02 17:42:44 +02:00 committed by GitHub
commit be9af9c249
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -110,17 +110,23 @@ static ARG_FILES: &str = "files";
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().after_help(AFTER_HELP).try_get_matches_from(args)?;
let matches = uu_app().try_get_matches_from(args)?;
let files: Vec<&OsStr> = matches
let files: Vec<_> = matches
.get_many::<OsString>(ARG_FILES)
.map(|v| v.map(OsString::as_os_str).collect())
.unwrap_or_default();
let force_flag = matches.get_flag(OPT_FORCE);
if files.is_empty() && !force_flag {
// Still check by hand and not use clap
// Because "rm -f" is a thing
return Err(UUsageError::new(1, "missing operand"));
}
// If -f(--force) is before any -i (or variants) we want prompts else no prompts
let force_prompt_never: bool = force_flag && {
let force_prompt_never = force_flag && {
let force_index = matches.index_of(OPT_FORCE).unwrap_or(0);
![OPT_PROMPT, OPT_PROMPT_MORE, OPT_INTERACTIVE]
.iter()
@ -130,11 +136,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
})
};
if files.is_empty() && !force_flag {
// Still check by hand and not use clap
// Because "rm -f" is a thing
return Err(UUsageError::new(1, "missing operand"));
} else {
let options = Options {
force: force_flag,
interactive: {
@ -194,7 +195,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if remove(&files, &options) {
return Err(1.into());
}
}
Ok(())
}
@ -203,6 +204,7 @@ pub fn uu_app() -> Command {
.version(uucore::crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.after_help(AFTER_HELP)
.infer_long_args(true)
.args_override_self(true)
.arg(