From 29694212dd9423ce3a221bc32cdf9636d941bde8 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 29 Dec 2024 16:36:14 +0100 Subject: [PATCH] refactor: simplify the code by using the clap function instead --- src/uu/chgrp/src/chgrp.rs | 13 ++++--------- src/uu/chmod/src/chmod.rs | 13 ++++--------- src/uu/chown/src/chown.rs | 13 ++++--------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 16f67144a..fe5aee872 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -63,7 +63,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> Command { - let mut cmd = Command::new(uucore::util_name()) + Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) @@ -126,12 +126,7 @@ pub fn uu_app() -> Command { .long(options::RECURSIVE) .help("operate on files and directories recursively") .action(ArgAction::SetTrue), - ); - - // Add common arguments with chgrp, chown & chmod - for arg in uucore::perms::common_args() { - cmd = cmd.arg(arg); - } - - cmd + ) + // Add common arguments with chgrp, chown & chmod + .args(uucore::perms::common_args()) } diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index f62f66503..c05288e21 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> Command { - let mut cmd = Command::new(uucore::util_name()) + Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) @@ -224,14 +224,9 @@ pub fn uu_app() -> Command { .required_unless_present(options::MODE) .action(ArgAction::Append) .value_hint(clap::ValueHint::AnyPath), - ); - - // Add common arguments with chgrp, chown & chmod - for arg in uucore::perms::common_args() { - cmd = cmd.arg(arg); - } - - cmd + ) + // Add common arguments with chgrp, chown & chmod + .args(uucore::perms::common_args()) } struct Chmoder { diff --git a/src/uu/chown/src/chown.rs b/src/uu/chown/src/chown.rs index d8cb14fa3..20bc87c34 100644 --- a/src/uu/chown/src/chown.rs +++ b/src/uu/chown/src/chown.rs @@ -77,7 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } pub fn uu_app() -> Command { - let mut cmd = Command::new(uucore::util_name()) + Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .override_usage(format_usage(USAGE)) @@ -152,14 +152,9 @@ pub fn uu_app() -> Command { .short('v') .help("output a diagnostic for every file processed") .action(ArgAction::SetTrue), - ); - - // Add common arguments with chgrp, chown & chmod - for arg in uucore::perms::common_args() { - cmd = cmd.arg(arg); - } - - cmd + ) + // Add common arguments with chgrp, chown & chmod + .args(uucore::perms::common_args()) } /// Parses the user string to extract the UID.