From 9e3871c6c545a3a3640e4bb4a59326c0d5ce7837 Mon Sep 17 00:00:00 2001 From: Alexander Bakanovskii Date: Fri, 19 Sep 2025 14:21:51 +0300 Subject: [PATCH] pinky: add --lookup flag --- src/uu/pinky/locales/en-US.ftl | 1 + src/uu/pinky/locales/fr-FR.ftl | 1 + src/uu/pinky/src/pinky.rs | 7 +++++++ src/uu/pinky/src/platform/unix.rs | 19 +++++++++++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/uu/pinky/locales/en-US.ftl b/src/uu/pinky/locales/en-US.ftl index 65b12d0ca..eba1148b7 100644 --- a/src/uu/pinky/locales/en-US.ftl +++ b/src/uu/pinky/locales/en-US.ftl @@ -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 diff --git a/src/uu/pinky/locales/fr-FR.ftl b/src/uu/pinky/locales/fr-FR.ftl index 3be28ec7a..ee37681c9 100644 --- a/src/uu/pinky/locales/fr-FR.ftl +++ b/src/uu/pinky/locales/fr-FR.ftl @@ -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 diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 942695654..1ba9d5a51 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -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"; @@ -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. diff --git a/src/uu/pinky/src/platform/unix.rs b/src/uu/pinky/src/platform/unix.rs index 1a749e6b9..8acc4cf2a 100644 --- a/src/uu/pinky/src/platform/unix.rs +++ b/src/uu/pinky/src/platform/unix.rs @@ -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; @@ -81,6 +84,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } let pk = Pinky { + do_lookup, include_idle, include_heading, include_fullname, @@ -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, @@ -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!();