pinky: add --lookup flag

This commit is contained in:
Alexander Bakanovskii
2025-09-19 15:08:24 +03:00
parent aaf742dcbe
commit 9e3871c6c5
4 changed files with 24 additions and 4 deletions
+1
View File
@@ -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
+1
View File
@@ -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
+7
View File
@@ -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.
+15 -4
View File
@@ -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!();