mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
install: update to clap 4
This commit is contained in:
parent
a3a50eb4ef
commit
a529a27a23
2 changed files with 56 additions and 46 deletions
|
@ -18,7 +18,7 @@ edition = "2021"
|
||||||
path = "src/install.rs"
|
path = "src/install.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
clap = { version = "4.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"
|
||||||
|
|
|
@ -12,7 +12,7 @@ mod mode;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use clap::{crate_version, Arg, ArgMatches, Command};
|
use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
||||||
use file_diff::diff;
|
use file_diff::diff;
|
||||||
use filetime::{set_file_times, FileTime};
|
use filetime::{set_file_times, FileTime};
|
||||||
use uucore::backup_control::{self, BackupMode};
|
use uucore::backup_control::{self, BackupMode};
|
||||||
|
@ -188,57 +188,63 @@ 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())
|
Command::new(uucore::util_name())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.override_usage(format_usage(USAGE))
|
.override_usage(format_usage(USAGE))
|
||||||
.infer_long_args(true)
|
.infer_long_args(true)
|
||||||
.arg(
|
.arg(backup_control::arguments::backup())
|
||||||
backup_control::arguments::backup()
|
.arg(backup_control::arguments::backup_no_args())
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
backup_control::arguments::backup_no_args()
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_IGNORED)
|
Arg::new(OPT_IGNORED)
|
||||||
.short('c')
|
.short('c')
|
||||||
.help("ignored")
|
.help("ignored")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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",
|
||||||
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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",
|
||||||
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
|
||||||
.arg(
|
.arg(
|
||||||
// TODO implement flag
|
// TODO implement flag
|
||||||
Arg::new(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",
|
||||||
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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)
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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)
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(OPT_OWNER)
|
Arg::new(OPT_OWNER)
|
||||||
|
@ -246,31 +252,33 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.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)
|
.value_hint(clap::ValueHint::Username),
|
||||||
.value_hint(clap::ValueHint::Username)
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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",
|
||||||
|
)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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)")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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")
|
||||||
.value_hint(clap::ValueHint::CommandName)
|
.value_hint(clap::ValueHint::CommandName),
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
backup_control::arguments::suffix()
|
|
||||||
)
|
)
|
||||||
|
.arg(backup_control::arguments::suffix())
|
||||||
.arg(
|
.arg(
|
||||||
// TODO implement flag
|
// TODO implement flag
|
||||||
Arg::new(OPT_TARGET_DIRECTORY)
|
Arg::new(OPT_TARGET_DIRECTORY)
|
||||||
|
@ -278,7 +286,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.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")
|
||||||
.value_hint(clap::ValueHint::DirPath)
|
.value_hint(clap::ValueHint::DirPath),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
// TODO implement flag
|
// TODO implement flag
|
||||||
|
@ -286,13 +294,14 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.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")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(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")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
// TODO implement flag
|
// TODO implement flag
|
||||||
|
@ -300,6 +309,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.short('P')
|
.short('P')
|
||||||
.long(OPT_PRESERVE_CONTEXT)
|
.long(OPT_PRESERVE_CONTEXT)
|
||||||
.help("(unimplemented) preserve security context")
|
.help("(unimplemented) preserve security context")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
// TODO implement flag
|
// TODO implement flag
|
||||||
|
@ -308,13 +318,13 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.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")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(ARG_FILES)
|
Arg::new(ARG_FILES)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.takes_value(true)
|
.num_args(1..)
|
||||||
.min_values(1)
|
.value_hint(clap::ValueHint::AnyPath),
|
||||||
.value_hint(clap::ValueHint::AnyPath)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,11 +338,11 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
fn check_unimplemented(matches: &ArgMatches) -> UResult<()> {
|
fn check_unimplemented(matches: &ArgMatches) -> UResult<()> {
|
||||||
if matches.contains_id(OPT_NO_TARGET_DIRECTORY) {
|
if matches.get_flag(OPT_NO_TARGET_DIRECTORY) {
|
||||||
Err(InstallError::Unimplemented(String::from("--no-target-directory, -T")).into())
|
Err(InstallError::Unimplemented(String::from("--no-target-directory, -T")).into())
|
||||||
} else if matches.contains_id(OPT_PRESERVE_CONTEXT) {
|
} else if matches.get_flag(OPT_PRESERVE_CONTEXT) {
|
||||||
Err(InstallError::Unimplemented(String::from("--preserve-context, -P")).into())
|
Err(InstallError::Unimplemented(String::from("--preserve-context, -P")).into())
|
||||||
} else if matches.contains_id(OPT_CONTEXT) {
|
} else if matches.get_flag(OPT_CONTEXT) {
|
||||||
Err(InstallError::Unimplemented(String::from("--context, -Z")).into())
|
Err(InstallError::Unimplemented(String::from("--context, -Z")).into())
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -348,7 +358,7 @@ fn check_unimplemented(matches: &ArgMatches) -> UResult<()> {
|
||||||
/// In event of failure, returns an integer intended as a program return code.
|
/// In event of failure, returns an integer intended as a program return code.
|
||||||
///
|
///
|
||||||
fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
||||||
let main_function = if matches.contains_id(OPT_DIRECTORY) {
|
let main_function = if matches.get_flag(OPT_DIRECTORY) {
|
||||||
MainFunction::Directory
|
MainFunction::Directory
|
||||||
} else {
|
} else {
|
||||||
MainFunction::Standard
|
MainFunction::Standard
|
||||||
|
@ -371,9 +381,9 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
||||||
.get_one::<String>(OPT_TARGET_DIRECTORY)
|
.get_one::<String>(OPT_TARGET_DIRECTORY)
|
||||||
.map(|d| d.to_owned());
|
.map(|d| d.to_owned());
|
||||||
|
|
||||||
let preserve_timestamps = matches.contains_id(OPT_PRESERVE_TIMESTAMPS);
|
let preserve_timestamps = matches.get_flag(OPT_PRESERVE_TIMESTAMPS);
|
||||||
let compare = matches.contains_id(OPT_COMPARE);
|
let compare = matches.get_flag(OPT_COMPARE);
|
||||||
let strip = matches.contains_id(OPT_STRIP);
|
let strip = matches.get_flag(OPT_STRIP);
|
||||||
if preserve_timestamps && compare {
|
if preserve_timestamps && compare {
|
||||||
show_error!("Options --compare and --preserve-timestamps are mutually exclusive");
|
show_error!("Options --compare and --preserve-timestamps are mutually exclusive");
|
||||||
return Err(1.into());
|
return Err(1.into());
|
||||||
|
@ -397,7 +407,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
||||||
.map(|s| s.as_str())
|
.map(|s| s.as_str())
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
verbose: matches.contains_id(OPT_VERBOSE),
|
verbose: matches.get_flag(OPT_VERBOSE),
|
||||||
preserve_timestamps,
|
preserve_timestamps,
|
||||||
compare,
|
compare,
|
||||||
strip,
|
strip,
|
||||||
|
@ -407,7 +417,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
|
||||||
.map(|s| s.as_str())
|
.map(|s| s.as_str())
|
||||||
.unwrap_or(DEFAULT_STRIP_PROGRAM),
|
.unwrap_or(DEFAULT_STRIP_PROGRAM),
|
||||||
),
|
),
|
||||||
create_leading: matches.contains_id(OPT_CREATE_LEADING),
|
create_leading: matches.get_flag(OPT_CREATE_LEADING),
|
||||||
target_dir,
|
target_dir,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue