mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (simplify enum element names/InteractiveMode)
This commit is contained in:
parent
fd8e5acd57
commit
82dc40f0af
1 changed files with 13 additions and 13 deletions
26
src/rm/rm.rs
26
src/rm/rm.rs
|
@ -26,9 +26,9 @@ use walkdir::{DirEntry, WalkDir};
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Copy)]
|
#[derive(Eq, PartialEq, Clone, Copy)]
|
||||||
enum InteractiveMode {
|
enum InteractiveMode {
|
||||||
InteractiveNone,
|
None,
|
||||||
InteractiveOnce,
|
Once,
|
||||||
InteractiveAlways,
|
Always,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
|
@ -112,18 +112,18 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
force,
|
force,
|
||||||
interactive: {
|
interactive: {
|
||||||
if matches.opt_present("i") {
|
if matches.opt_present("i") {
|
||||||
InteractiveMode::InteractiveAlways
|
InteractiveMode::Always
|
||||||
} else if matches.opt_present("I") {
|
} else if matches.opt_present("I") {
|
||||||
InteractiveMode::InteractiveOnce
|
InteractiveMode::Once
|
||||||
} else if matches.opt_present("interactive") {
|
} else if matches.opt_present("interactive") {
|
||||||
match &matches.opt_str("interactive").unwrap()[..] {
|
match &matches.opt_str("interactive").unwrap()[..] {
|
||||||
"none" => InteractiveMode::InteractiveNone,
|
"none" => InteractiveMode::None,
|
||||||
"once" => InteractiveMode::InteractiveOnce,
|
"once" => InteractiveMode::Once,
|
||||||
"always" => InteractiveMode::InteractiveAlways,
|
"always" => InteractiveMode::Always,
|
||||||
val => crash!(1, "Invalid argument to interactive ({})", val),
|
val => crash!(1, "Invalid argument to interactive ({})", val),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InteractiveMode::InteractiveNone
|
InteractiveMode::None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
one_fs: matches.opt_present("one-file-system"),
|
one_fs: matches.opt_present("one-file-system"),
|
||||||
|
@ -132,7 +132,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
dir: matches.opt_present("dir"),
|
dir: matches.opt_present("dir"),
|
||||||
verbose: matches.opt_present("verbose"),
|
verbose: matches.opt_present("verbose"),
|
||||||
};
|
};
|
||||||
if options.interactive == InteractiveMode::InteractiveOnce
|
if options.interactive == InteractiveMode::Once
|
||||||
&& (options.recursive || matches.free.len() > 3)
|
&& (options.recursive || matches.free.len() > 3)
|
||||||
{
|
{
|
||||||
let msg = if options.recursive {
|
let msg = if options.recursive {
|
||||||
|
@ -192,7 +192,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
|
||||||
|
|
||||||
let is_root = path.has_root() && path.parent().is_none();
|
let is_root = path.has_root() && path.parent().is_none();
|
||||||
if options.recursive && (!is_root || !options.preserve_root) {
|
if options.recursive && (!is_root || !options.preserve_root) {
|
||||||
if options.interactive != InteractiveMode::InteractiveAlways {
|
if options.interactive != InteractiveMode::Always {
|
||||||
// we need the extra crate because apparently fs::remove_dir_all() does not function
|
// we need the extra crate because apparently fs::remove_dir_all() does not function
|
||||||
// correctly on Windows
|
// correctly on Windows
|
||||||
if let Err(e) = remove_dir_all(path) {
|
if let Err(e) = remove_dir_all(path) {
|
||||||
|
@ -240,7 +240,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_dir(path: &Path, options: &Options) -> bool {
|
fn remove_dir(path: &Path, options: &Options) -> bool {
|
||||||
let response = if options.interactive == InteractiveMode::InteractiveAlways {
|
let response = if options.interactive == InteractiveMode::Always {
|
||||||
prompt_file(path, true)
|
prompt_file(path, true)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
@ -261,7 +261,7 @@ fn remove_dir(path: &Path, options: &Options) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_file(path: &Path, options: &Options) -> bool {
|
fn remove_file(path: &Path, options: &Options) -> bool {
|
||||||
let response = if options.interactive == InteractiveMode::InteractiveAlways {
|
let response = if options.interactive == InteractiveMode::Always {
|
||||||
prompt_file(path, false)
|
prompt_file(path, false)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue