From 75044c1bc47321d8b360045693dd386515e27fa9 Mon Sep 17 00:00:00 2001 From: KAA the Wise Date: Fri, 22 Sep 2023 18:41:31 +0300 Subject: [PATCH 1/4] rm: make option types public Made `Options` and `InteractiveMode` public and added documentation for them. --- src/uu/rm/src/rm.rs | 50 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index d9421d0ae..96e0fa7aa 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -18,22 +18,52 @@ use uucore::{format_usage, help_about, help_section, help_usage, prompt_yes, sho use walkdir::{DirEntry, WalkDir}; #[derive(Eq, PartialEq, Clone, Copy)] -enum InteractiveMode { +/// Enum, determining when the `rm` will prompt the user about the file deletion +pub enum InteractiveMode { + /// Never prompt Never, + /// Prompt once before removing more than three files, or when removing + /// recursively. Once, + /// Prompt before every removal Always, + /// TODO clarify what this option does PromptProtected, } -struct Options { - force: bool, - interactive: InteractiveMode, +/// Options for the `rm` command +/// +/// All options are public so that the options can be programmatically +/// constructed by other crates, such as Nushell. That means that this struct +/// is part of our public API. It should therefore not be changed without good +/// reason. +/// +/// The fields are documented with the arguments that determine their value. +pub struct Options { + /// `-f`, `--force` + pub force: bool, + /// Iterative mode, determines when the command will prompt. + /// + /// Set by the following arguments: + /// - `-i`: [`InteractiveMode::Always`] + /// - `-I`: [`InteractiveMode::Once`] + /// - `--interactive`: sets one of the above or [`InteractiveMode::Never`] + /// - `-f`: implicitly sets [`InteractiveMode::Never`] + /// + /// If no other option sets this mode, [`InteractiveMode::PromptProtected`] + /// is used + pub interactive: InteractiveMode, #[allow(dead_code)] - one_fs: bool, - preserve_root: bool, - recursive: bool, - dir: bool, - verbose: bool, + /// `--one-file-system` + pub one_fs: bool, + /// `--preserve-root`/`--no-preserve-root` + pub preserve_root: bool, + /// `-r`, `--recursive` + pub recursive: bool, + /// `-d`, `--dir` + pub dir: bool, + /// `-v`, `--verbose` + pub verbose: bool, } const ABOUT: &str = help_about!("rm.md"); @@ -268,7 +298,7 @@ fn remove(files: &[&OsStr], options: &Options) -> bool { // TODO: actually print out the specific error // TODO: When the error is not about missing files // (e.g., permission), even rm -f should fail with - // outputting the error, but there's no easy eay. + // outputting the error, but there's no easy way. if options.force { false } else { From 20fb473da852d9b09a592b258c4c183c3d97dc64 Mon Sep 17 00:00:00 2001 From: KAA the Wise Date: Fri, 22 Sep 2023 19:17:51 +0300 Subject: [PATCH 2/4] rm: make the `remove` function public --- src/uu/rm/src/rm.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 96e0fa7aa..19c749cf0 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -279,7 +279,13 @@ pub fn uu_app() -> Command { } // TODO: implement one-file-system (this may get partially implemented in walkdir) -fn remove(files: &[&OsStr], options: &Options) -> bool { +/// Remove (or unlink) the given files +/// +/// Returns true if it has encountered an error. +/// +/// Behavior is determined by the `options` parameter, see [`Options`] for +/// details. +pub fn remove(files: &[&OsStr], options: &Options) -> bool { let mut had_err = false; for filename in files { From 30f1fceddcd77c79ec505b4dfad9b28e4d786d18 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Sep 2023 09:29:00 +0200 Subject: [PATCH 3/4] add nushell to the list of ignored names --- .vscode/cspell.dictionaries/acronyms+names.wordlist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/cspell.dictionaries/acronyms+names.wordlist.txt b/.vscode/cspell.dictionaries/acronyms+names.wordlist.txt index 8711913d9..c004ea2f8 100644 --- a/.vscode/cspell.dictionaries/acronyms+names.wordlist.txt +++ b/.vscode/cspell.dictionaries/acronyms+names.wordlist.txt @@ -58,6 +58,7 @@ MinGW Minix NetBSD Novell +Nushell OpenBSD POSIX PowerPC From 4b76b2f33220b268f3ac148fa3ac0a110947b5a1 Mon Sep 17 00:00:00 2001 From: KAA the Wise Date: Sat, 23 Sep 2023 15:55:57 +0300 Subject: [PATCH 4/4] rm: document PromptProtected interactive mode option --- src/uu/rm/src/rm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 19c749cf0..87767b904 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -27,7 +27,7 @@ pub enum InteractiveMode { Once, /// Prompt before every removal Always, - /// TODO clarify what this option does + /// Prompt only on write-protected files PromptProtected, }