hostname: fix -d flag (#8657)

* hostname: fix -d flag

* tests/hostname: test -d when no domain
This commit is contained in:
alexander
2025-10-15 22:07:54 -04:00
committed by GitHub
parent af766713c5
commit 517b5fb8b3
2 changed files with 16 additions and 1 deletions
+3 -1
View File
@@ -177,8 +177,10 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> {
} else {
println!("{}", &hostname[ci.0 + 1..]);
}
return Ok(());
} else if matches.get_flag(OPT_SHORT) {
println!("{hostname}");
}
return Ok(());
}
println!("{hostname}");
+13
View File
@@ -37,3 +37,16 @@ fn test_hostname_full() {
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
}
#[test]
fn test_hostname_domain_empty() {
let fqdn = new_ucmd!().arg("-f").succeeds();
let short = new_ucmd!().arg("-s").succeeds();
let domain = new_ucmd!().arg("-d").succeeds();
let domain_short = new_ucmd!().arg("-sd").succeeds();
if fqdn.stdout() == short.stdout() {
assert!(domain.stdout().is_empty());
assert!(domain_short.stdout().is_empty());
}
}