From 97f40b0aee9cf4af8724891eba058b1afbf4248d Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 17 Mar 2021 10:16:31 +0100 Subject: [PATCH 1/3] rm: add an additional flag -R for --recursive make clap support -R in addition to -r --- src/uu/rm/src/rm.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 4c81c97ccbc..190fe9794a5 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -48,6 +48,7 @@ static OPT_PRESERVE_ROOT: &str = "preserve-root"; static OPT_PROMPT: &str = "prompt"; static OPT_PROMPT_MORE: &str = "prompt-more"; static OPT_RECURSIVE: &str = "recursive"; +static OPT_RECURSIVE_R: &str = "recursive_R"; static OPT_VERBOSE: &str = "verbose"; static ARG_FILES: &str = "files"; @@ -58,7 +59,7 @@ fn get_usage() -> String { fn get_long_usage() -> String { String::from( - "By default, rm does not remove directories. Use the --recursive (-r) + "By default, rm does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents To remove a file whose name starts with a '-', for example '-foo', @@ -82,7 +83,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .about(ABOUT) .usage(&usage[..]) .after_help(&long_usage[..]) - // TODO: make getopts support -R in addition to -r .arg( Arg::with_name(OPT_FORCE) @@ -128,6 +128,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .long(OPT_RECURSIVE) .help("remove directories and their contents recursively") ) + .arg( + Arg::with_name(OPT_RECURSIVE_R).short("R") + .help("Equivalent to -r") + ) .arg( Arg::with_name(OPT_DIR) .short("d") @@ -182,7 +186,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { }, one_fs: matches.is_present(OPT_ONE_FILE_SYSTEM), preserve_root: !matches.is_present(OPT_NO_PRESERVE_ROOT), - recursive: matches.is_present(OPT_RECURSIVE), + recursive: matches.is_present(OPT_RECURSIVE) || matches.is_present(OPT_RECURSIVE_R), dir: matches.is_present(OPT_DIR), verbose: matches.is_present(OPT_VERBOSE), }; @@ -283,7 +287,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool { had_err = true; } else { show_error!( - "could not remove directory '{}' (did you mean to pass '-r'?)", + "could not remove directory '{}' (did you mean to pass '-r' or '-R'?)", path.display() ); had_err = true; From 867e117c99a0b3e7e3ca3c902ab92875f4234d46 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 17 Mar 2021 10:20:08 +0100 Subject: [PATCH 2/3] Update test_rm.rs --- tests/by-util/test_rm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index f9a4dd0d5d9..27568957a75 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -148,7 +148,7 @@ fn test_rm_errors() { // rm: error: could not remove directory 'test_rm_errors_directory' (did you mean to pass '-r'?) ucmd.arg(dir).fails().stderr_is( "rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \ - to pass '-r'?)\n", + to pass '-r' or '-R'?)\n", ); } From d9adec34967f4e641937fcbedeb0aab4784aa287 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Wed, 17 Mar 2021 14:46:25 +0100 Subject: [PATCH 3/3] add comment --- src/uu/rm/src/rm.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 190fe9794a5..466a8d6c1b9 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -129,6 +129,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .help("remove directories and their contents recursively") ) .arg( + // To mimic GNU's behavior we also want the '-R' flag. However, using clap's + // alias method 'visible_alias("R")' would result in a long '--R' flag. Arg::with_name(OPT_RECURSIVE_R).short("R") .help("Equivalent to -r") )