1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

install: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 13:45:35 +01:00
parent 8c58f8e2b1
commit 89112fb1c2
3 changed files with 33 additions and 43 deletions

View file

@ -18,7 +18,7 @@ edition = "2018"
path = "src/install.rs" path = "src/install.rs"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
filetime = "0.2" filetime = "0.2"
file_diff = "1.0.0" file_diff = "1.0.0"
libc = ">= 0.2" libc = ">= 0.2"

View file

@ -175,7 +175,7 @@ fn usage() -> String {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().override_usage(&usage[..]).get_matches_from(args);
let paths: Vec<String> = matches let paths: Vec<String> = matches
.values_of(ARG_FILES) .values_of(ARG_FILES)
@ -192,7 +192,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -203,67 +203,67 @@ pub fn uu_app() -> App<'static, 'static> {
backup_control::arguments::backup_no_args() backup_control::arguments::backup_no_args()
) )
.arg( .arg(
Arg::with_name(OPT_IGNORED) Arg::new(OPT_IGNORED)
.short("c") .short('c')
.help("ignored") .help("ignored")
) )
.arg( .arg(
Arg::with_name(OPT_COMPARE) Arg::new(OPT_COMPARE)
.short("C") .short('C')
.long(OPT_COMPARE) .long(OPT_COMPARE)
.help("compare each pair of source and destination files, and in some cases, do not modify the destination at all") .help("compare each pair of source and destination files, and in some cases, do not modify the destination at all")
) )
.arg( .arg(
Arg::with_name(OPT_DIRECTORY) Arg::new(OPT_DIRECTORY)
.short("d") .short('d')
.long(OPT_DIRECTORY) .long(OPT_DIRECTORY)
.help("treat all arguments as directory names. create all components of the specified directories") .help("treat all arguments as directory names. create all components of the specified directories")
) )
.arg( .arg(
// TODO implement flag // TODO implement flag
Arg::with_name(OPT_CREATE_LEADING) Arg::new(OPT_CREATE_LEADING)
.short("D") .short('D')
.help("create all leading components of DEST except the last, then copy SOURCE to DEST") .help("create all leading components of DEST except the last, then copy SOURCE to DEST")
) )
.arg( .arg(
Arg::with_name(OPT_GROUP) Arg::new(OPT_GROUP)
.short("g") .short('g')
.long(OPT_GROUP) .long(OPT_GROUP)
.help("set group ownership, instead of process's current group") .help("set group ownership, instead of process's current group")
.value_name("GROUP") .value_name("GROUP")
.takes_value(true) .takes_value(true)
) )
.arg( .arg(
Arg::with_name(OPT_MODE) Arg::new(OPT_MODE)
.short("m") .short('m')
.long(OPT_MODE) .long(OPT_MODE)
.help("set permission mode (as in chmod), instead of rwxr-xr-x") .help("set permission mode (as in chmod), instead of rwxr-xr-x")
.value_name("MODE") .value_name("MODE")
.takes_value(true) .takes_value(true)
) )
.arg( .arg(
Arg::with_name(OPT_OWNER) Arg::new(OPT_OWNER)
.short("o") .short('o')
.long(OPT_OWNER) .long(OPT_OWNER)
.help("set ownership (super-user only)") .help("set ownership (super-user only)")
.value_name("OWNER") .value_name("OWNER")
.takes_value(true) .takes_value(true)
) )
.arg( .arg(
Arg::with_name(OPT_PRESERVE_TIMESTAMPS) Arg::new(OPT_PRESERVE_TIMESTAMPS)
.short("p") .short('p')
.long(OPT_PRESERVE_TIMESTAMPS) .long(OPT_PRESERVE_TIMESTAMPS)
.help("apply access/modification times of SOURCE files to corresponding destination files") .help("apply access/modification times of SOURCE files to corresponding destination files")
) )
.arg( .arg(
Arg::with_name(OPT_STRIP) Arg::new(OPT_STRIP)
.short("s") .short('s')
.long(OPT_STRIP) .long(OPT_STRIP)
.help("strip symbol tables (no action Windows)") .help("strip symbol tables (no action Windows)")
) )
.arg( .arg(
Arg::with_name(OPT_STRIP_PROGRAM) Arg::new(OPT_STRIP_PROGRAM)
.long(OPT_STRIP_PROGRAM) .long(OPT_STRIP_PROGRAM)
.help("program used to strip binaries (no action Windows)") .help("program used to strip binaries (no action Windows)")
.value_name("PROGRAM") .value_name("PROGRAM")
@ -273,42 +273,42 @@ pub fn uu_app() -> App<'static, 'static> {
) )
.arg( .arg(
// TODO implement flag // TODO implement flag
Arg::with_name(OPT_TARGET_DIRECTORY) Arg::new(OPT_TARGET_DIRECTORY)
.short("t") .short('t')
.long(OPT_TARGET_DIRECTORY) .long(OPT_TARGET_DIRECTORY)
.help("move all SOURCE arguments into DIRECTORY") .help("move all SOURCE arguments into DIRECTORY")
.value_name("DIRECTORY") .value_name("DIRECTORY")
) )
.arg( .arg(
// TODO implement flag // TODO implement flag
Arg::with_name(OPT_NO_TARGET_DIRECTORY) Arg::new(OPT_NO_TARGET_DIRECTORY)
.short("T") .short('T')
.long(OPT_NO_TARGET_DIRECTORY) .long(OPT_NO_TARGET_DIRECTORY)
.help("(unimplemented) treat DEST as a normal file") .help("(unimplemented) treat DEST as a normal file")
) )
.arg( .arg(
Arg::with_name(OPT_VERBOSE) Arg::new(OPT_VERBOSE)
.short("v") .short('v')
.long(OPT_VERBOSE) .long(OPT_VERBOSE)
.help("explain what is being done") .help("explain what is being done")
) )
.arg( .arg(
// TODO implement flag // TODO implement flag
Arg::with_name(OPT_PRESERVE_CONTEXT) Arg::new(OPT_PRESERVE_CONTEXT)
.short("P") .short('P')
.long(OPT_PRESERVE_CONTEXT) .long(OPT_PRESERVE_CONTEXT)
.help("(unimplemented) preserve security context") .help("(unimplemented) preserve security context")
) )
.arg( .arg(
// TODO implement flag // TODO implement flag
Arg::with_name(OPT_CONTEXT) Arg::new(OPT_CONTEXT)
.short("Z") .short('Z')
.long(OPT_CONTEXT) .long(OPT_CONTEXT)
.help("(unimplemented) set security context of files and directories") .help("(unimplemented) set security context of files and directories")
.value_name("CONTEXT") .value_name("CONTEXT")
) )
.arg(Arg::with_name(ARG_FILES).multiple(true).takes_value(true).min_values(1)) .arg(Arg::new(ARG_FILES).multiple_occurrences(true).takes_value(true).min_values(1))
} }
/// Check for unimplemented command line arguments. /// Check for unimplemented command line arguments.

View file

@ -9,16 +9,6 @@ use std::process::Command;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use std::thread::sleep; use std::thread::sleep;
#[test]
fn test_install_help() {
let (_, mut ucmd) = at_and_ucmd!();
ucmd.arg("--help")
.succeeds()
.no_stderr()
.stdout_contains("FLAGS:");
}
#[test] #[test]
fn test_install_basic() { fn test_install_basic() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();