Skip to content

Commit 517b5fb

Browse files
authored
hostname: fix -d flag (#8657)
* hostname: fix -d flag * tests/hostname: test -d when no domain
1 parent af76671 commit 517b5fb

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/uu/hostname/src/hostname.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> {
177177
} else {
178178
println!("{}", &hostname[ci.0 + 1..]);
179179
}
180-
return Ok(());
180+
} else if matches.get_flag(OPT_SHORT) {
181+
println!("{hostname}");
181182
}
183+
return Ok(());
182184
}
183185

184186
println!("{hostname}");

tests/by-util/test_hostname.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,16 @@ fn test_hostname_full() {
3737
fn test_invalid_arg() {
3838
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
3939
}
40+
41+
#[test]
42+
fn test_hostname_domain_empty() {
43+
let fqdn = new_ucmd!().arg("-f").succeeds();
44+
let short = new_ucmd!().arg("-s").succeeds();
45+
let domain = new_ucmd!().arg("-d").succeeds();
46+
let domain_short = new_ucmd!().arg("-sd").succeeds();
47+
48+
if fqdn.stdout() == short.stdout() {
49+
assert!(domain.stdout().is_empty());
50+
assert!(domain_short.stdout().is_empty());
51+
}
52+
}

0 commit comments

Comments
 (0)