Skip to content
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
1 change: 1 addition & 0 deletions src/uu/pinky/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pinky-help-omit-headings = omit the line of column headings in short format
pinky-help-omit-name = omit the user's full name in short format
pinky-help-omit-name-host = omit the user's full name and remote host in short format
pinky-help-omit-name-host-time = omit the user's full name, remote host and idle time in short format
pinky-help-lookup = attempt to canonicalize hostnames via DNS
pinky-help-help = Print help information

# Column headers for short format
Expand Down
1 change: 1 addition & 0 deletions src/uu/pinky/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pinky-help-omit-headings = omettre la ligne des en-têtes de colonnes en format
pinky-help-omit-name = omettre le nom complet de l'utilisateur en format court
pinky-help-omit-name-host = omettre le nom complet et l'hôte distant de l'utilisateur en format court
pinky-help-omit-name-host-time = omettre le nom complet, l'hôte distant et le temps d'inactivité de l'utilisateur en format court
pinky-help-lookup = tenter de donner un forme canonique aux noms d'hôte avec DNS
pinky-help-help = Afficher les informations d'aide

# En-têtes de colonnes pour le format court
Expand Down
7 changes: 7 additions & 0 deletions src/uu/pinky/src/pinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod platform;

mod options {
pub const LONG_FORMAT: &str = "long_format";
pub const LOOKUP: &str = "lookup";
pub const OMIT_HOME_DIR: &str = "omit_home_dir";
pub const OMIT_PROJECT_FILE: &str = "omit_project_file";
pub const OMIT_PLAN_FILE: &str = "omit_plan_file";
Expand Down Expand Up @@ -101,6 +102,12 @@ pub fn uu_app() -> Command {
.action(ArgAction::Append)
.value_hint(clap::ValueHint::Username),
)
.arg(
Arg::new(options::LOOKUP)
.long(options::LOOKUP)
.help(translate!("pinky-help-lookup"))
.action(ArgAction::SetTrue),
)
.arg(
// Redefine the help argument to not include the short flag
// since that conflicts with omit_project_file.
Expand Down
19 changes: 15 additions & 4 deletions src/uu/pinky/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// if true, use the "short" output format.
let do_short_format = !matches.get_flag(options::LONG_FORMAT);

// If true, attempt to canonicalize hostname via a DNS lookup.
let do_lookup = matches.get_flag(options::LOOKUP);

/* if true, display the ut_host field. */
let mut include_where = true;

Expand All @@ -81,6 +84,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

let pk = Pinky {
do_lookup,
include_idle,
include_heading,
include_fullname,
Expand All @@ -103,6 +107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

struct Pinky {
do_lookup: bool,
include_idle: bool,
include_heading: bool,
include_fullname: bool,
Expand Down Expand Up @@ -206,10 +211,16 @@ impl Pinky {

print!(" {}", time_string(ut));

let mut s = ut.host();
if self.include_where && !s.is_empty() {
s = ut.canon_host()?;
print!(" {s}");
if self.include_where {
let s: String = if self.do_lookup {
ut.canon_host().unwrap_or(ut.host())
} else {
ut.host()
};

if !s.is_empty() {
print!(" {s}");
}
}

println!();
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_pinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ fn test_short_format_i() {
assert_eq!(v_actual, v_expect);
}

#[cfg(unix)]
#[test]
#[cfg(not(target_os = "openbsd"))]
fn test_lookup() {
let args = ["--lookup"];
let ts = TestScenario::new(util_name!());
let actual = ts.ucmd().args(&args).succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &[])).stdout_move_str();
let v_actual: Vec<&str> = actual.split_whitespace().collect();
let v_expect: Vec<&str> = expect.split_whitespace().collect();
assert_eq!(v_actual, v_expect);
}

#[cfg(unix)]
#[test]
#[cfg(not(target_os = "openbsd"))]
Expand Down
Loading