From 88d47ac379b7ea3f059ff3bdb4b9bddd346524a8 Mon Sep 17 00:00:00 2001 From: naoNao89 <90588855+naoNao89@users.noreply.github.com> Date: Sat, 11 Oct 2025 19:59:39 +0700 Subject: [PATCH] pwd: add -h/-V short flags for help/version This adds -h and -V as short alternatives for --help and --version. GNU pwd only supports the long forms, but most other uutils accept both. Having the short flags makes pwd consistent with the rest of the utilities and more convenient to use. Changes: - Added .short('h') and .short('V') to help/version args - Updated tests to verify both short and long forms work - Localization already in place for both English and French --- src/uu/pwd/locales/en-US.ftl | 2 ++ src/uu/pwd/locales/fr-FR.ftl | 2 ++ src/uu/pwd/src/pwd.rs | 16 ++++++++++++++++ tests/by-util/test_pwd.rs | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/src/uu/pwd/locales/en-US.ftl b/src/uu/pwd/locales/en-US.ftl index ffed18f37..ac1bc56ec 100644 --- a/src/uu/pwd/locales/en-US.ftl +++ b/src/uu/pwd/locales/en-US.ftl @@ -4,6 +4,8 @@ pwd-usage = pwd [OPTION]... # Help messages pwd-help-logical = use PWD from environment, even if it contains symlinks pwd-help-physical = avoid all symlinks +pwd-help-text = Print help information +pwd-version-text = Print version information # Error messages pwd-error-failed-to-get-current-directory = failed to get current directory diff --git a/src/uu/pwd/locales/fr-FR.ftl b/src/uu/pwd/locales/fr-FR.ftl index 95a79a362..703598c32 100644 --- a/src/uu/pwd/locales/fr-FR.ftl +++ b/src/uu/pwd/locales/fr-FR.ftl @@ -4,6 +4,8 @@ pwd-usage = pwd [OPTION]... # Messages d'aide pwd-help-logical = utiliser PWD de l'environnement, même s'il contient des liens symboliques pwd-help-physical = éviter tous les liens symboliques +pwd-help-text = Afficher l'aide +pwd-version-text = Afficher les informations de version # Messages d'erreur pwd-error-failed-to-get-current-directory = échec de l'obtention du répertoire actuel diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index cefdee898..9f588ac84 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -145,6 +145,22 @@ pub fn uu_app() -> Command { .about(translate!("pwd-about")) .override_usage(format_usage(&translate!("pwd-usage"))) .infer_long_args(true) + .disable_help_flag(true) + .disable_version_flag(true) + .arg( + Arg::new("help") + .short('h') + .long("help") + .help(translate!("pwd-help-text")) + .action(ArgAction::Help), + ) + .arg( + Arg::new("version") + .short('V') + .long("version") + .help(translate!("pwd-version-text")) + .action(ArgAction::Version), + ) .arg( Arg::new(OPT_LOGICAL) .short('L') diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index ce63fb889..b749d2958 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -15,6 +15,42 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails_with_code(1); } +#[test] +fn test_help() { + new_ucmd!() + .arg("--help") + .succeeds() + .stdout_contains("Display the full filename of the current working directory") + .stdout_contains("--help") + .stdout_contains("--version"); +} + +#[test] +fn test_version() { + new_ucmd!() + .arg("--version") + .succeeds() + .stdout_contains("uutils coreutils"); +} + +#[test] +fn test_short_help() { + new_ucmd!() + .arg("-h") + .succeeds() + .stdout_contains("Display the full filename of the current working directory") + .stdout_contains("-h"); +} + +#[test] +fn test_short_version() { + new_ucmd!() + .arg("-V") + .succeeds() + .stdout_contains("pwd") + .stdout_contains("uutils coreutils"); +} + #[test] fn test_default() { let (at, mut ucmd) = at_and_ucmd!();