From c1e642b353bd03672de02b676a96958b72fa3dd7 Mon Sep 17 00:00:00 2001 From: Krysztal Huang Date: Mon, 8 Jul 2024 17:03:17 +0800 Subject: [PATCH] pidof: Introduce `pgrep` as dependence. --- Cargo.lock | 1 + src/uu/pidof/Cargo.toml | 1 + src/uu/pidof/src/pidof.rs | 73 ++++++++++++++++++++++++++++++++------- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b01f7b9..ef2eaff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -873,6 +873,7 @@ name = "uu_pidof" version = "0.0.1" dependencies = [ "clap", + "uu_pgrep", "uucore", ] diff --git a/src/uu/pidof/Cargo.toml b/src/uu/pidof/Cargo.toml index ffe306f..cf9df16 100644 --- a/src/uu/pidof/Cargo.toml +++ b/src/uu/pidof/Cargo.toml @@ -15,6 +15,7 @@ categories = ["command-line-utilities"] [dependencies] uucore = { workspace = true } clap = { workspace = true } +uu_pgrep = { path = "../pgrep" } [lib] path = "src/pidof.rs" diff --git a/src/uu/pidof/src/pidof.rs b/src/uu/pidof/src/pidof.rs index aad3afb..54e78c9 100644 --- a/src/uu/pidof/src/pidof.rs +++ b/src/uu/pidof/src/pidof.rs @@ -19,19 +19,68 @@ pub fn uu_app() -> Command { .infer_long_args(true) .disable_help_flag(true) .disable_version_flag(true) - .arg(Arg::new("program-name")) - .args([ - arg!(-c "Return PIDs with the same root directory").action(ArgAction::SetTrue), - arg!(-d "Use the provided character as output separator"), - arg!(-h "Display this help text").action(ArgAction::Help), - arg!(-n "Avoid using stat system function on network shares") + .arg( + Arg::new("program-name") + .help("Program name.") + .required(true) + .index(1), + ) + .arg( + Arg::new("c") + .short('c') + .help("Return PIDs with the same root directory") .action(ArgAction::SetTrue), - arg!(-o "Omit results with a given PID").action(ArgAction::Set), - arg!(-q "Quiet mode. Do not display output").action(ArgAction::SetTrue), - arg!(-s "Only return one PID").action(ArgAction::SetTrue), - arg!(-x "Return PIDs of shells running scripts with a matching name") + ) + .arg( + Arg::new("d") + .short('d') + .help("Use the provided character as output separator") + .action(ArgAction::Set) + .value_name("sep") + .default_value(" ") + .hide_default_value(true), + ) + .arg( + Arg::new("help") + .short('h') + .help("Display this help text") + .action(ArgAction::Help), + ) + .arg( + Arg::new("n") + .short('n') + .help("Avoid using stat system function on network shares") .action(ArgAction::SetTrue), - arg!(-z "List zombie and I/O waiting processes. May cause pidof to hang.") + ) + .arg( + Arg::new("o") + .short('o') + .help("Omit results with a given PID") + .action(ArgAction::Set) + .value_name("pid"), + ) + .arg( + Arg::new("q") + .short('q') + .help("Quiet mode. Do not display output") .action(ArgAction::SetTrue), - ]) + ) + .arg( + Arg::new("s") + .short('s') + .help("Only return one PID") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("x") + .short('x') + .help("Return PIDs of shells running scripts with a matching name") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("z") + .short('z') + .help("List zombie and I/O waiting processes. May cause pidof to hang.") + .action(ArgAction::SetTrue), + ) }