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]
uucore_procs = { version=">=0.0.16", path="../uucore_procs" }
clap = "3.2"
clap = "4.0"
dns-lookup = { version="1.0.5", optional=true }
dunce = "1.0.3"
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"] }
[dev-dependencies]
clap = "3.2"
clap = "4.0"
once_cell = "1.13"
[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,
/// from `ArgMatches`.
/// `groups_only` determines whether verbose output will only mention the group.
pub fn chown_base<'a>(
mut command: Command<'a>,
pub fn chown_base(
mut command: Command,
args: impl crate::Args,
add_arg_if_not_reference: &'a str,
add_arg_if_not_reference: &'static str,
parse_gid_uid_and_filter: GidUidFilterParser,
groups_only: bool,
) -> UResult<()> {
@ -449,19 +449,16 @@ pub fn chown_base<'a>(
command = command.arg(
Arg::new(add_arg_if_not_reference)
.value_name(add_arg_if_not_reference)
.required(true)
.takes_value(true)
.multiple_occurrences(false),
.required(true),
);
}
command = command.arg(
Arg::new(options::ARG_FILES)
.value_name(options::ARG_FILES)
.value_hint(clap::ValueHint::FilePath)
.multiple_occurrences(true)
.takes_value(true)
.action(clap::ArgAction::Append)
.required(true)
.min_values(1),
.num_args(1..),
);
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())
.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)
} else if matches.contains_id(options::dereference::NO_DEREFERENCE) {
} else if matches.get_flag(options::dereference::NO_DEREFERENCE) {
Some(false)
} else {
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
} else if matches.contains_id(options::traverse::EVERY) {
} else if matches.get_flag(options::traverse::EVERY) {
TraverseSymlinks::All
} else {
TraverseSymlinks::None
};
let recursive = matches.contains_id(options::RECURSIVE);
let recursive = matches.get_flag(options::RECURSIVE);
if recursive {
if traverse_symlinks == TraverseSymlinks::None {
if dereference == Some(true) {
@ -500,13 +497,13 @@ pub fn chown_base<'a>(
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
} else if matches.contains_id(options::verbosity::SILENT)
|| matches.contains_id(options::verbosity::QUIET)
} else if matches.get_flag(options::verbosity::SILENT)
|| matches.get_flag(options::verbosity::QUIET)
{
VerbosityLevel::Silent
} else if matches.contains_id(options::verbosity::VERBOSE) {
} else if matches.get_flag(options::verbosity::VERBOSE) {
VerbosityLevel::Verbose
} else {
VerbosityLevel::Normal

View file

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

View file

@ -674,7 +674,9 @@ impl UError for ClapErrorWrapper {
// If the error is a DisplayHelp or DisplayVersion variant,
// we don't want to apply the custom error code, but leave
// 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
} else {
self.code