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

refactor: simplify the code by using the clap function instead

This commit is contained in:
Sylvestre Ledru 2024-12-29 16:36:14 +01:00
parent e45c56b926
commit 29694212dd
3 changed files with 12 additions and 27 deletions

View file

@ -63,7 +63,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
let mut cmd = 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))
@ -126,12 +126,7 @@ 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),
); )
// Add common arguments with chgrp, chown & chmod
// Add common arguments with chgrp, chown & chmod .args(uucore::perms::common_args())
for arg in uucore::perms::common_args() {
cmd = cmd.arg(arg);
}
cmd
} }

View file

@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
let mut cmd = 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))
@ -224,14 +224,9 @@ pub fn uu_app() -> Command {
.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 common arguments with chgrp, chown & chmod
// Add common arguments with chgrp, chown & chmod .args(uucore::perms::common_args())
for arg in uucore::perms::common_args() {
cmd = cmd.arg(arg);
}
cmd
} }
struct Chmoder { struct Chmoder {

View file

@ -77,7 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
let mut cmd = 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))
@ -152,14 +152,9 @@ pub fn uu_app() -> Command {
.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 common arguments with chgrp, chown & chmod
// Add common arguments with chgrp, chown & chmod .args(uucore::perms::common_args())
for arg in uucore::perms::common_args() {
cmd = cmd.arg(arg);
}
cmd
} }
/// Parses the user string to extract the UID. /// Parses the user string to extract the UID.