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 {
|
pub fn uu_app() -> Command {
|
||||||
Command::new(uucore::util_name())
|
let mut cmd = 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))
|
||||||
|
@ -140,24 +140,12 @@ pub fn uu_app() -> Command {
|
||||||
.long(options::RECURSIVE)
|
.long(options::RECURSIVE)
|
||||||
.help("operate on files and directories recursively")
|
.help("operate on files and directories recursively")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
);
|
||||||
.arg(
|
|
||||||
Arg::new(options::traverse::TRAVERSE)
|
// Add traverse-related arguments
|
||||||
.short(options::traverse::TRAVERSE.chars().next().unwrap())
|
for arg in uucore::perms::traverse_args() {
|
||||||
.help("if a command line argument is a symbolic link to a directory, traverse it")
|
cmd = cmd.arg(arg);
|
||||||
.action(ArgAction::SetTrue),
|
}
|
||||||
)
|
|
||||||
.arg(
|
cmd
|
||||||
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),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> Command {
|
pub fn uu_app() -> Command {
|
||||||
Command::new(uucore::util_name())
|
let mut cmd = 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))
|
||||||
|
@ -206,16 +206,24 @@ pub fn uu_app() -> Command {
|
||||||
.help("use RFILE's mode instead of MODE values"),
|
.help("use RFILE's mode instead of MODE values"),
|
||||||
)
|
)
|
||||||
.arg(
|
.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),
|
||||||
// however .multiple_occurrences(true) cannot be used here because FILE already needs that.
|
// It would be nice if clap could parse with delimiter, e.g. "g-x,u+x",
|
||||||
// Only one positional argument with .multiple_occurrences(true) set is allowed per command
|
// 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
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::FILE)
|
Arg::new(options::FILE)
|
||||||
.required_unless_present(options::MODE)
|
.required_unless_present(options::MODE)
|
||||||
.action(ArgAction::Append)
|
.action(ArgAction::Append)
|
||||||
.value_hint(clap::ValueHint::AnyPath),
|
.value_hint(clap::ValueHint::AnyPath),
|
||||||
)
|
);
|
||||||
|
|
||||||
|
// Add traverse-related arguments
|
||||||
|
for arg in uucore::perms::traverse_args() {
|
||||||
|
cmd = cmd.arg(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Chmoder {
|
struct Chmoder {
|
||||||
|
|
|
@ -77,7 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> Command {
|
pub fn uu_app() -> Command {
|
||||||
Command::new(uucore::util_name())
|
let mut cmd = 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))
|
||||||
|
@ -165,34 +165,20 @@ pub fn uu_app() -> Command {
|
||||||
.long(options::verbosity::SILENT)
|
.long(options::verbosity::SILENT)
|
||||||
.action(ArgAction::SetTrue),
|
.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(
|
||||||
Arg::new(options::verbosity::VERBOSE)
|
Arg::new(options::verbosity::VERBOSE)
|
||||||
.long(options::verbosity::VERBOSE)
|
.long(options::verbosity::VERBOSE)
|
||||||
.short('v')
|
.short('v')
|
||||||
.help("output a diagnostic for every file processed")
|
.help("output a diagnostic for every file processed")
|
||||||
.action(ArgAction::SetTrue),
|
.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.
|
/// Parses the user string to extract the UID.
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub use crate::features::entries;
|
||||||
use crate::show_error;
|
use crate::show_error;
|
||||||
use clap::{Arg, ArgMatches, Command};
|
use clap::{Arg, ArgMatches, Command};
|
||||||
use libc::{gid_t, uid_t};
|
use libc::{gid_t, uid_t};
|
||||||
|
use options::traverse;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
|
@ -634,6 +635,26 @@ pub fn chown_base(
|
||||||
executor.exec()
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue