Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id: Handle repeated flags, recognize conflict between pretty-print and passwd file-entry #6288

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -396,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(
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -456,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'");
}
Loading