From e978fe538276ffcf4b7a10dafc47d01fd3c9e29d Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 28 Apr 2024 22:39:14 +0200 Subject: [PATCH 1/2] id: permit repeated flags --- src/uu/id/src/id.rs | 1 + tests/by-util/test_id.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index b8fb51d79db..fe605a33c4e 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -324,6 +324,7 @@ pub fn uu_app() -> Command { .about(ABOUT) .override_usage(format_usage(USAGE)) .infer_long_args(true) + .args_override_self(true) .arg( Arg::new(options::OPT_AUDIT) .short('A') diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index 5c2a67199c6..e51f3e5427e 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -327,6 +327,11 @@ fn test_id_default_format() { .args(&args) .succeeds() .stdout_only(unwrap_or_return!(expected_result(&ts, &args)).stdout_str()); + let args = [opt2, opt2]; + ts.ucmd() + .args(&args) + .succeeds() + .stdout_only(unwrap_or_return!(expected_result(&ts, &args)).stdout_str()); } } From 4f5a3b47161df72546c7cf8d5e0f5ef60bfdb294 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 28 Apr 2024 23:05:43 +0200 Subject: [PATCH 2/2] id: mark passwd-format and pretty-print as conflicting These are non-sensical to combine, and didn't work reasonably anyway. Also, passwd-formatting is our own extension, so there is no need for compatibility anyway. --- src/uu/id/src/id.rs | 1 + tests/by-util/test_id.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index fe605a33c4e..e803708bdce 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -397,6 +397,7 @@ pub fn uu_app() -> Command { Arg::new(options::OPT_PASSWORD) .short('P') .help("Display the id as a password file entry.") + .conflicts_with(options::OPT_HUMAN_READABLE) .action(ArgAction::SetTrue), ) .arg( diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index e51f3e5427e..070ed011e26 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -461,3 +461,16 @@ fn test_id_no_specified_user_posixly() { } } } + +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_id_pretty_print_password_record() { + // `-p` is BSD only and not supported on GNU's `id`. + // `-P` is our own extension, and not supported by either GNU nor BSD. + // These must conflict, because they both set the output format. + new_ucmd!() + .arg("-p") + .arg("-P") + .fails() + .stderr_contains("the argument '-p' cannot be used with '-P'"); +}