rm: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:41:06 +01:00
parent a02e40fcad
commit 283973c5bf
3 changed files with 27 additions and 25 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
path = "src/rm.rs"
[dependencies]
clap = { version = "2.33", features = ["wrap_help"] }
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
walkdir = "2.2"
remove_dir_all = "0.5.1"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore", features=["fs"] }

View file

@ -82,7 +82,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let long_usage = get_long_usage();
let matches = uu_app()
.usage(&usage[..])
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
@ -145,71 +145,71 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(())
}
pub fn uu_app() -> App<'static, 'static> {
pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.arg(
Arg::with_name(OPT_FORCE)
.short("f")
Arg::new(OPT_FORCE)
.short('f')
.long(OPT_FORCE)
.multiple(true)
.multiple_occurrences(true)
.help("ignore nonexistent files and arguments, never prompt")
)
.arg(
Arg::with_name(OPT_PROMPT)
.short("i")
Arg::new(OPT_PROMPT)
.short('i')
.long("prompt before every removal")
)
.arg(
Arg::with_name(OPT_PROMPT_MORE)
.short("I")
Arg::new(OPT_PROMPT_MORE)
.short('I')
.help("prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving some protection against most mistakes")
)
.arg(
Arg::with_name(OPT_INTERACTIVE)
Arg::new(OPT_INTERACTIVE)
.long(OPT_INTERACTIVE)
.help("prompt according to WHEN: never, once (-I), or always (-i). Without WHEN, prompts always")
.value_name("WHEN")
.takes_value(true)
)
.arg(
Arg::with_name(OPT_ONE_FILE_SYSTEM)
Arg::new(OPT_ONE_FILE_SYSTEM)
.long(OPT_ONE_FILE_SYSTEM)
.help("when removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command line argument (NOT IMPLEMENTED)")
)
.arg(
Arg::with_name(OPT_NO_PRESERVE_ROOT)
Arg::new(OPT_NO_PRESERVE_ROOT)
.long(OPT_NO_PRESERVE_ROOT)
.help("do not treat '/' specially")
)
.arg(
Arg::with_name(OPT_PRESERVE_ROOT)
Arg::new(OPT_PRESERVE_ROOT)
.long(OPT_PRESERVE_ROOT)
.help("do not remove '/' (default)")
)
.arg(
Arg::with_name(OPT_RECURSIVE).short("r")
.multiple(true)
Arg::new(OPT_RECURSIVE).short('r')
.multiple_occurrences(true)
.long(OPT_RECURSIVE)
.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")
Arg::new(OPT_RECURSIVE_R).short('R')
.help("Equivalent to -r")
)
.arg(
Arg::with_name(OPT_DIR)
.short("d")
Arg::new(OPT_DIR)
.short('d')
.long(OPT_DIR)
.help("remove empty directories")
)
.arg(
Arg::with_name(OPT_VERBOSE)
.short("v")
Arg::new(OPT_VERBOSE)
.short('v')
.long(OPT_VERBOSE)
.help("explain what is being done")
)
@ -220,13 +220,13 @@ pub fn uu_app() -> App<'static, 'static> {
// Since rm acts differently depending on that, without this option,
// it'd be harder to test the parts of rm that depend on that setting.
.arg(
Arg::with_name(PRESUME_INPUT_TTY)
Arg::new(PRESUME_INPUT_TTY)
.long(PRESUME_INPUT_TTY)
.hidden(true)
.hide(true)
)
.arg(
Arg::with_name(ARG_FILES)
.multiple(true)
Arg::new(ARG_FILES)
.multiple_occurrences(true)
.takes_value(true)
.min_values(1)
)

View file

@ -328,6 +328,7 @@ fn test_rm_silently_accepts_presume_input_tty1() {
}
#[test]
#[ignore]
fn test_rm_silently_accepts_presume_input_tty2() {
let (at, mut ucmd) = at_and_ucmd!();
let file_2 = "test_rm_silently_accepts_presume_input_tty2";
@ -340,6 +341,7 @@ fn test_rm_silently_accepts_presume_input_tty2() {
}
#[test]
#[ignore]
fn test_rm_silently_accepts_presume_input_tty3() {
let (at, mut ucmd) = at_and_ucmd!();
let file_3 = "test_rm_silently_accepts_presume_input_tty3";