1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

uucore: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 15:29:16 +02:00
parent 7a3cb35352
commit 9605c7f135
4 changed files with 30 additions and 31 deletions

View file

@ -19,7 +19,7 @@ path="src/lib/lib.rs"
[dependencies] [dependencies]
uucore_procs = { version=">=0.0.16", path="../uucore_procs" } uucore_procs = { version=">=0.0.16", path="../uucore_procs" }
clap = "3.2" clap = "4.0"
dns-lookup = { version="1.0.5", optional=true } dns-lookup = { version="1.0.5", optional=true }
dunce = "1.0.3" dunce = "1.0.3"
wild = "2.0" wild = "2.0"
@ -41,7 +41,7 @@ walkdir = { version="2.3.2", optional=true }
nix = { version = "0.25", optional = true, default-features = false, features = ["fs", "uio", "zerocopy"] } nix = { version = "0.25", optional = true, default-features = false, features = ["fs", "uio", "zerocopy"] }
[dev-dependencies] [dev-dependencies]
clap = "3.2" clap = "4.0"
once_cell = "1.13" once_cell = "1.13"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]

View file

@ -421,10 +421,10 @@ type GidUidFilterParser = fn(&ArgMatches) -> UResult<(Option<u32>, Option<u32>,
/// `parse_gid_uid_and_filter` will be called to obtain the target gid and uid, and the filter, /// `parse_gid_uid_and_filter` will be called to obtain the target gid and uid, and the filter,
/// from `ArgMatches`. /// from `ArgMatches`.
/// `groups_only` determines whether verbose output will only mention the group. /// `groups_only` determines whether verbose output will only mention the group.
pub fn chown_base<'a>( pub fn chown_base(
mut command: Command<'a>, mut command: Command,
args: impl crate::Args, args: impl crate::Args,
add_arg_if_not_reference: &'a str, add_arg_if_not_reference: &'static str,
parse_gid_uid_and_filter: GidUidFilterParser, parse_gid_uid_and_filter: GidUidFilterParser,
groups_only: bool, groups_only: bool,
) -> UResult<()> { ) -> UResult<()> {
@ -449,19 +449,16 @@ pub fn chown_base<'a>(
command = command.arg( command = command.arg(
Arg::new(add_arg_if_not_reference) Arg::new(add_arg_if_not_reference)
.value_name(add_arg_if_not_reference) .value_name(add_arg_if_not_reference)
.required(true) .required(true),
.takes_value(true)
.multiple_occurrences(false),
); );
} }
command = command.arg( command = command.arg(
Arg::new(options::ARG_FILES) Arg::new(options::ARG_FILES)
.value_name(options::ARG_FILES) .value_name(options::ARG_FILES)
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.multiple_occurrences(true) .action(clap::ArgAction::Append)
.takes_value(true)
.required(true) .required(true)
.min_values(1), .num_args(1..),
); );
let matches = command.try_get_matches_from(args)?; let matches = command.try_get_matches_from(args)?;
@ -470,25 +467,25 @@ pub fn chown_base<'a>(
.map(|v| v.map(ToString::to_string).collect()) .map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default(); .unwrap_or_default();
let preserve_root = matches.contains_id(options::preserve_root::PRESERVE); let preserve_root = matches.get_flag(options::preserve_root::PRESERVE);
let mut dereference = if matches.contains_id(options::dereference::DEREFERENCE) { let mut dereference = if matches.get_flag(options::dereference::DEREFERENCE) {
Some(true) Some(true)
} else if matches.contains_id(options::dereference::NO_DEREFERENCE) { } else if matches.get_flag(options::dereference::NO_DEREFERENCE) {
Some(false) Some(false)
} else { } else {
None None
}; };
let mut traverse_symlinks = if matches.contains_id(options::traverse::TRAVERSE) { let mut traverse_symlinks = if matches.get_flag(options::traverse::TRAVERSE) {
TraverseSymlinks::First TraverseSymlinks::First
} else if matches.contains_id(options::traverse::EVERY) { } else if matches.get_flag(options::traverse::EVERY) {
TraverseSymlinks::All TraverseSymlinks::All
} else { } else {
TraverseSymlinks::None TraverseSymlinks::None
}; };
let recursive = matches.contains_id(options::RECURSIVE); let recursive = matches.get_flag(options::RECURSIVE);
if recursive { if recursive {
if traverse_symlinks == TraverseSymlinks::None { if traverse_symlinks == TraverseSymlinks::None {
if dereference == Some(true) { if dereference == Some(true) {
@ -500,13 +497,13 @@ pub fn chown_base<'a>(
traverse_symlinks = TraverseSymlinks::None; traverse_symlinks = TraverseSymlinks::None;
} }
let verbosity_level = if matches.contains_id(options::verbosity::CHANGES) { let verbosity_level = if matches.get_flag(options::verbosity::CHANGES) {
VerbosityLevel::Changes VerbosityLevel::Changes
} else if matches.contains_id(options::verbosity::SILENT) } else if matches.get_flag(options::verbosity::SILENT)
|| matches.contains_id(options::verbosity::QUIET) || matches.get_flag(options::verbosity::QUIET)
{ {
VerbosityLevel::Silent VerbosityLevel::Silent
} else if matches.contains_id(options::verbosity::VERBOSE) { } else if matches.get_flag(options::verbosity::VERBOSE) {
VerbosityLevel::Verbose VerbosityLevel::Verbose
} else { } else {
VerbosityLevel::Normal VerbosityLevel::Normal

View file

@ -47,8 +47,8 @@
//! .arg(backup_control::arguments::backup()) //! .arg(backup_control::arguments::backup())
//! .arg(backup_control::arguments::backup_no_args()) //! .arg(backup_control::arguments::backup_no_args())
//! .arg(backup_control::arguments::suffix()) //! .arg(backup_control::arguments::suffix())
//! .override_usage(&usage[..]) //! .override_usage(usage)
//! .after_help(&*format!( //! .after_help(format!(
//! "{}\n{}", //! "{}\n{}",
//! long_usage, //! long_usage,
//! backup_control::BACKUP_CONTROL_LONG_HELP //! backup_control::BACKUP_CONTROL_LONG_HELP
@ -205,30 +205,30 @@ pub mod arguments {
pub static OPT_SUFFIX: &str = "backupopt_suffix"; pub static OPT_SUFFIX: &str = "backupopt_suffix";
/// '--backup' argument /// '--backup' argument
pub fn backup<'a>() -> clap::Arg<'a> { pub fn backup() -> clap::Arg {
clap::Arg::new(OPT_BACKUP) clap::Arg::new(OPT_BACKUP)
.long("backup") .long("backup")
.help("make a backup of each existing destination file") .help("make a backup of each existing destination file")
.takes_value(true) .action(clap::ArgAction::Set)
.require_equals(true) .require_equals(true)
.min_values(0) .num_args(0..=1)
.value_name("CONTROL") .value_name("CONTROL")
} }
/// '-b' argument /// '-b' argument
pub fn backup_no_args<'a>() -> clap::Arg<'a> { pub fn backup_no_args() -> clap::Arg {
clap::Arg::new(OPT_BACKUP_NO_ARG) clap::Arg::new(OPT_BACKUP_NO_ARG)
.short('b') .short('b')
.help("like --backup but does not accept an argument") .help("like --backup but does not accept an argument")
} }
/// '-S, --suffix' argument /// '-S, --suffix' argument
pub fn suffix<'a>() -> clap::Arg<'a> { pub fn suffix() -> clap::Arg {
clap::Arg::new(OPT_SUFFIX) clap::Arg::new(OPT_SUFFIX)
.short('S') .short('S')
.long("suffix") .long("suffix")
.help("override the usual backup suffix") .help("override the usual backup suffix")
.takes_value(true) .action(clap::ArgAction::Set)
.value_name("SUFFIX") .value_name("SUFFIX")
.allow_hyphen_values(true) .allow_hyphen_values(true)
} }
@ -460,7 +460,7 @@ mod tests {
// Environment variable for "VERSION_CONTROL" // Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL"; static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";
fn make_app() -> clap::Command<'static> { fn make_app() -> clap::Command {
Command::new("command") Command::new("command")
.arg(arguments::backup()) .arg(arguments::backup())
.arg(arguments::backup_no_args()) .arg(arguments::backup_no_args())

View file

@ -674,7 +674,9 @@ impl UError for ClapErrorWrapper {
// If the error is a DisplayHelp or DisplayVersion variant, // If the error is a DisplayHelp or DisplayVersion variant,
// we don't want to apply the custom error code, but leave // we don't want to apply the custom error code, but leave
// it 0. // it 0.
if let clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion = self.error.kind() { if let clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion =
self.error.kind()
{
0 0
} else { } else {
self.code self.code