mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-07 16:37:48 +00:00
Cleaner force_prompt_never
This commit is contained in:
parent
b3b90e453c
commit
b612ce5cd7
1 changed files with 8 additions and 37 deletions
|
@ -88,47 +88,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let force_flag = matches.get_flag(OPT_FORCE);
|
let force_flag = matches.get_flag(OPT_FORCE);
|
||||||
|
|
||||||
// If -f(--force) is before any -i (or variants) we want prompts else no prompts
|
// If -f(--force) is before any -i (or variants) we want prompts else no prompts
|
||||||
let force_prompt_never: bool = if force_flag {
|
let force_prompt_never: bool = force_flag && {
|
||||||
if matches.value_source(OPT_FORCE) == Some(ValueSource::CommandLine) {
|
if matches.value_source(OPT_FORCE) == Some(ValueSource::CommandLine) {
|
||||||
if let Some(force_index) = matches.index_of(OPT_FORCE) {
|
let force_index = matches.index_of(OPT_FORCE).unwrap_or(0);
|
||||||
let mut result = true;
|
[OPT_PROMPT, OPT_PROMPT_MORE, OPT_INTERACTIVE]
|
||||||
|
.iter()
|
||||||
// if we have rm -i -f
|
.any(|opt| {
|
||||||
if matches.value_source(OPT_PROMPT) == Some(ValueSource::CommandLine) {
|
matches.value_source(opt) == Some(ValueSource::CommandLine)
|
||||||
if let Some(prompt_index) = matches.index_of(OPT_PROMPT) {
|
&& matches.index_of(opt).unwrap_or(0) < force_index
|
||||||
if result {
|
})
|
||||||
result = prompt_index <= force_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have rm -I -f
|
|
||||||
if matches.value_source(OPT_PROMPT_MORE) == Some(ValueSource::CommandLine) {
|
|
||||||
if let Some(prompt_more_index_index) = matches.index_of(OPT_PROMPT_MORE) {
|
|
||||||
if result {
|
|
||||||
result = prompt_more_index_index <= force_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have rm --interactive -f
|
|
||||||
if matches.value_source(OPT_INTERACTIVE) == Some(ValueSource::CommandLine) {
|
|
||||||
if let Some(interactive_index) = matches.index_of(OPT_INTERACTIVE) {
|
|
||||||
if result {
|
|
||||||
result = interactive_index <= force_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if files.is_empty() && !force_flag {
|
if files.is_empty() && !force_flag {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue