Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/uu/hostname/src/hostname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// spell-checker:ignore hashset Addrs addrs

use std::io::{Write, stdout};
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd")))]
use std::net::ToSocketAddrs;
use std::str;
Expand Down Expand Up @@ -164,7 +165,7 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> {
}
let len = output.len();
if len > 0 {
println!("{}", &output[0..len - 1]);
writeln!(stdout(), "{}", &output[0..len - 1])?;
}

Ok(())
Expand All @@ -173,17 +174,17 @@ fn display_hostname(matches: &ArgMatches) -> UResult<()> {
let mut it = hostname.char_indices().filter(|&ci| ci.1 == '.');
if let Some(ci) = it.next() {
if matches.get_flag(OPT_SHORT) {
println!("{}", &hostname[0..ci.0]);
writeln!(stdout(), "{}", &hostname[0..ci.0])?;
} else {
println!("{}", &hostname[ci.0 + 1..]);
writeln!(stdout(), "{}", &hostname[ci.0 + 1..])?;
}
} else if matches.get_flag(OPT_SHORT) {
println!("{hostname}");
writeln!(stdout(), "{hostname}")?;
}
return Ok(());
}

println!("{hostname}");
writeln!(stdout(), "{hostname}")?;

Ok(())
}
Expand Down
Loading