From 624700f835c70d560841258811e23295f0cc6930 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 29 Sep 2022 15:29:57 +0200 Subject: [PATCH] chown: update to clap 4 --- src/uu/chown/Cargo.toml | 2 +- src/uu/chown/src/chown.rs | 46 +++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/uu/chown/Cargo.toml b/src/uu/chown/Cargo.toml index 736a0328d..cb425e819 100644 --- a/src/uu/chown/Cargo.toml +++ b/src/uu/chown/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/chown.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "fs", "perms"] } [[bin]] diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index 2aefb4879..d99516d92 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -14,7 +14,7 @@ use uucore::perms::{chown_base, options, IfFrom}; use uucore::error::{FromIo, UResult, USimpleError}; -use clap::{crate_version, Arg, ArgMatches, Command}; +use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::fs; use std::os::unix::fs::MetadataExt; @@ -63,22 +63,25 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { ) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) .infer_long_args(true) + .disable_help_flag(true) .arg( Arg::new(options::HELP) .long(options::HELP) - .help("Print help information."), + .help("Print help information.") + .action(ArgAction::Help), ) .arg( Arg::new(options::verbosity::CHANGES) .short('c') .long(options::verbosity::CHANGES) - .help("like verbose but report only when a change is made"), + .help("like verbose but report only when a change is made") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::dereference::DEREFERENCE) @@ -86,7 +89,8 @@ pub fn uu_app<'a>() -> Command<'a> { .help( "affect the referent of each symbolic link (this is the default), \ rather than the symbolic link itself", - ), + ) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::dereference::NO_DEREFERENCE) @@ -95,7 +99,8 @@ pub fn uu_app<'a>() -> Command<'a> { .help( "affect symbolic links instead of any referenced file \ (useful only on systems that can change the ownership of a symlink)", - ), + ) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::FROM) @@ -111,23 +116,27 @@ pub fn uu_app<'a>() -> Command<'a> { .arg( Arg::new(options::preserve_root::PRESERVE) .long(options::preserve_root::PRESERVE) - .help("fail to operate recursively on '/'"), + .help("fail to operate recursively on '/'") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::preserve_root::NO_PRESERVE) .long(options::preserve_root::NO_PRESERVE) - .help("do not treat '/' specially (the default)"), + .help("do not treat '/' specially (the default)") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::verbosity::QUIET) .long(options::verbosity::QUIET) - .help("suppress most error messages"), + .help("suppress most error messages") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::RECURSIVE) .short('R') .long(options::RECURSIVE) - .help("operate on files and directories recursively"), + .help("operate on files and directories recursively") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::REFERENCE) @@ -135,36 +144,41 @@ pub fn uu_app<'a>() -> Command<'a> { .help("use RFILE's owner and group rather than specifying OWNER:GROUP values") .value_name("RFILE") .value_hint(clap::ValueHint::FilePath) - .min_values(1), + .num_args(1..), ) .arg( Arg::new(options::verbosity::SILENT) .short('f') - .long(options::verbosity::SILENT), + .long(options::verbosity::SILENT) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::traverse::TRAVERSE) .short(options::traverse::TRAVERSE.chars().next().unwrap()) .help("if a command line argument is a symbolic link to a directory, traverse it") - .overrides_with_all(&[options::traverse::EVERY, options::traverse::NO_TRAVERSE]), + .overrides_with_all(&[options::traverse::EVERY, options::traverse::NO_TRAVERSE]) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::traverse::EVERY) .short(options::traverse::EVERY.chars().next().unwrap()) .help("traverse every symbolic link to a directory encountered") - .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE]), + .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::NO_TRAVERSE]) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::traverse::NO_TRAVERSE) .short(options::traverse::NO_TRAVERSE.chars().next().unwrap()) .help("do not traverse any symbolic links (default)") - .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]), + .overrides_with_all(&[options::traverse::TRAVERSE, options::traverse::EVERY]) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::verbosity::VERBOSE) .long(options::verbosity::VERBOSE) .short('v') - .help("output a diagnostic for every file processed"), + .help("output a diagnostic for every file processed") + .action(ArgAction::SetTrue), ) }