Skip to content

Commit 88d47ac

Browse files
committed
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
1 parent 8d59e08 commit 88d47ac

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/uu/pwd/locales/en-US.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pwd-usage = pwd [OPTION]...
44
# Help messages
55
pwd-help-logical = use PWD from environment, even if it contains symlinks
66
pwd-help-physical = avoid all symlinks
7+
pwd-help-text = Print help information
8+
pwd-version-text = Print version information
79
810
# Error messages
911
pwd-error-failed-to-get-current-directory = failed to get current directory

src/uu/pwd/locales/fr-FR.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pwd-usage = pwd [OPTION]...
44
# Messages d'aide
55
pwd-help-logical = utiliser PWD de l'environnement, même s'il contient des liens symboliques
66
pwd-help-physical = éviter tous les liens symboliques
7+
pwd-help-text = Afficher l'aide
8+
pwd-version-text = Afficher les informations de version
79
810
# Messages d'erreur
911
pwd-error-failed-to-get-current-directory = échec de l'obtention du répertoire actuel

src/uu/pwd/src/pwd.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ pub fn uu_app() -> Command {
145145
.about(translate!("pwd-about"))
146146
.override_usage(format_usage(&translate!("pwd-usage")))
147147
.infer_long_args(true)
148+
.disable_help_flag(true)
149+
.disable_version_flag(true)
150+
.arg(
151+
Arg::new("help")
152+
.short('h')
153+
.long("help")
154+
.help(translate!("pwd-help-text"))
155+
.action(ArgAction::Help),
156+
)
157+
.arg(
158+
Arg::new("version")
159+
.short('V')
160+
.long("version")
161+
.help(translate!("pwd-version-text"))
162+
.action(ArgAction::Version),
163+
)
148164
.arg(
149165
Arg::new(OPT_LOGICAL)
150166
.short('L')

tests/by-util/test_pwd.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@ fn test_invalid_arg() {
1515
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
1616
}
1717

18+
#[test]
19+
fn test_help() {
20+
new_ucmd!()
21+
.arg("--help")
22+
.succeeds()
23+
.stdout_contains("Display the full filename of the current working directory")
24+
.stdout_contains("--help")
25+
.stdout_contains("--version");
26+
}
27+
28+
#[test]
29+
fn test_version() {
30+
new_ucmd!()
31+
.arg("--version")
32+
.succeeds()
33+
.stdout_contains("uutils coreutils");
34+
}
35+
36+
#[test]
37+
fn test_short_help() {
38+
new_ucmd!()
39+
.arg("-h")
40+
.succeeds()
41+
.stdout_contains("Display the full filename of the current working directory")
42+
.stdout_contains("-h");
43+
}
44+
45+
#[test]
46+
fn test_short_version() {
47+
new_ucmd!()
48+
.arg("-V")
49+
.succeeds()
50+
.stdout_contains("pwd")
51+
.stdout_contains("uutils coreutils");
52+
}
53+
1854
#[test]
1955
fn test_default() {
2056
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)