Merge pull request #8669 from bakanovskii/add-pinky-lookup-flag

pinky: add --lookup flag
This commit is contained in:
Daniel Hofstetter
2025-09-19 16:57:42 +02:00
committed by GitHub
5 changed files with 37 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,
@@ -215,10 +220,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!();
+13
View File
@@ -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"))]