mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-15 12:27:49 +00:00
ch*: refactor duplicate declarations
This commit is contained in:
parent
80ed8d514a
commit
836351dd7a
4 changed files with 52 additions and 49 deletions
|
@ -63,7 +63,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let mut cmd = Command::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
|
@ -140,24 +140,12 @@ pub fn uu_app() -> Command {
|
|||
.long(options::RECURSIVE)
|
||||
.help("operate on files and directories recursively")
|
||||
.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")
|
||||
.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])
|
||||
.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")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
);
|
||||
|
||||
// Add traverse-related arguments
|
||||
for arg in uucore::perms::traverse_args() {
|
||||
cmd = cmd.arg(arg);
|
||||
}
|
||||
|
||||
cmd
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let mut cmd = Command::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
|
@ -206,7 +206,8 @@ pub fn uu_app() -> Command {
|
|||
.help("use RFILE's mode instead of MODE values"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::MODE).required_unless_present(options::REFERENCE), // It would be nice if clap could parse with delimiter, e.g. "g-x,u+x",
|
||||
Arg::new(options::MODE).required_unless_present(options::REFERENCE),
|
||||
// It would be nice if clap could parse with delimiter, e.g. "g-x,u+x",
|
||||
// however .multiple_occurrences(true) cannot be used here because FILE already needs that.
|
||||
// Only one positional argument with .multiple_occurrences(true) set is allowed per command
|
||||
)
|
||||
|
@ -215,7 +216,14 @@ pub fn uu_app() -> Command {
|
|||
.required_unless_present(options::MODE)
|
||||
.action(ArgAction::Append)
|
||||
.value_hint(clap::ValueHint::AnyPath),
|
||||
)
|
||||
);
|
||||
|
||||
// Add traverse-related arguments
|
||||
for arg in uucore::perms::traverse_args() {
|
||||
cmd = cmd.arg(arg);
|
||||
}
|
||||
|
||||
cmd
|
||||
}
|
||||
|
||||
struct Chmoder {
|
||||
|
|
|
@ -77,7 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
let mut cmd = Command::new(uucore::util_name())
|
||||
.version(crate_version!())
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
|
@ -165,34 +165,20 @@ pub fn uu_app() -> Command {
|
|||
.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])
|
||||
.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])
|
||||
.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])
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::verbosity::VERBOSE)
|
||||
.long(options::verbosity::VERBOSE)
|
||||
.short('v')
|
||||
.help("output a diagnostic for every file processed")
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
);
|
||||
|
||||
// Add traverse-related arguments
|
||||
for arg in uucore::perms::traverse_args() {
|
||||
cmd = cmd.arg(arg);
|
||||
}
|
||||
|
||||
cmd
|
||||
}
|
||||
|
||||
/// Parses the user string to extract the UID.
|
||||
|
|
|
@ -13,6 +13,7 @@ pub use crate::features::entries;
|
|||
use crate::show_error;
|
||||
use clap::{Arg, ArgMatches, Command};
|
||||
use libc::{gid_t, uid_t};
|
||||
use options::traverse;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use std::io::Error as IOError;
|
||||
|
@ -634,6 +635,26 @@ pub fn chown_base(
|
|||
executor.exec()
|
||||
}
|
||||
|
||||
pub fn traverse_args() -> Vec<Arg> {
|
||||
vec![
|
||||
Arg::new(traverse::TRAVERSE)
|
||||
.short(traverse::TRAVERSE.chars().next().unwrap())
|
||||
.help("if a command line argument is a symbolic link to a directory, traverse it")
|
||||
.overrides_with_all([traverse::EVERY, traverse::NO_TRAVERSE])
|
||||
.action(clap::ArgAction::SetTrue),
|
||||
Arg::new(traverse::EVERY)
|
||||
.short(traverse::EVERY.chars().next().unwrap())
|
||||
.help("traverse every symbolic link to a directory encountered")
|
||||
.overrides_with_all([traverse::TRAVERSE, traverse::NO_TRAVERSE])
|
||||
.action(clap::ArgAction::SetTrue),
|
||||
Arg::new(traverse::NO_TRAVERSE)
|
||||
.short(traverse::NO_TRAVERSE.chars().next().unwrap())
|
||||
.help("do not traverse any symbolic links (default)")
|
||||
.overrides_with_all([traverse::TRAVERSE, traverse::EVERY])
|
||||
.action(clap::ArgAction::SetTrue),
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue