diff --git a/src/uu/skill/src/skill.rs b/src/uu/skill/src/skill.rs index e1c47c6c..baf322ee 100644 --- a/src/uu/skill/src/skill.rs +++ b/src/uu/skill/src/skill.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use clap::{arg, crate_version, value_parser, Arg, Command}; +use clap::{crate_version, Arg, Command}; #[cfg(unix)] use nix::{sys::signal, sys::signal::Signal, unistd::Pid}; use uu_snice::{ @@ -29,6 +29,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // Case1: Send signal + let take_action = !matches.get_flag("no-action"); if let Some(targets) = settings.expressions { let pids = collect_pids(&targets); @@ -43,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; #[cfg(unix)] - let results = perform_action(&pids, &signal); + let results = perform_action(&pids, &signal, take_action); #[cfg(not(unix))] let results: Vec> = Vec::new(); @@ -54,6 +55,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if settings.verbose { let output = construct_verbose_result(&pids, &results).trim().to_owned(); println!("{output}"); + } else if !take_action { + pids.iter().for_each(|pid| println!("{pid}")); } } @@ -61,16 +64,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } #[cfg(unix)] -fn perform_action(pids: &[u32], signal: &Signal) -> Vec> { +fn perform_action(pids: &[u32], signal: &Signal, take_action: bool) -> Vec> { + let sig = if take_action { Some(*signal) } else { None }; pids.iter() .map(|pid| { - { - Some(match signal::kill(Pid::from_raw(*pid as i32), *signal) { - Ok(_) => ActionResult::Success, - - Err(_) => ActionResult::PermissionDenied, - }) - } + Some(match signal::kill(Pid::from_raw(*pid as i32), sig) { + Ok(_) => ActionResult::Success, + Err(_) => ActionResult::PermissionDenied, + }) }) .collect() } @@ -84,23 +85,5 @@ pub fn uu_app() -> Command { .infer_long_args(true) .arg_required_else_help(true) .arg(Arg::new("signal")) - .args([ - // arg!(-f --fast "fast mode (not implemented)"), - // arg!(-i --interactive "interactive"), - arg!(-l --list "list all signal names"), - arg!(-L --table "list all signal names in a nice table"), - // arg!(-n --"no-action" "do not actually kill processes; just print what would happen"), - arg!(-v --verbose "explain what is being done"), - // arg!(-w --warnings "enable warnings (not implemented)"), - // Expressions - arg!(-c --command ... "expression is a command name"), - arg!(-p --pid ... "expression is a process id number") - .value_parser(value_parser!(u32)), - arg!(-t --tty ... "expression is a terminal"), - arg!(-u --user ... "expression is a username"), - // arg!(--ns "match the processes that belong to the same namespace as "), - // arg!(--nslist "list which namespaces will be considered for the --ns option.") - // .value_delimiter(',') - // .value_parser(["ipc", "mnt", "net", "pid", "user", "uts"]), - ]) + .args(uu_snice::clap_args()) } diff --git a/src/uu/snice/src/snice.rs b/src/uu/snice/src/snice.rs index 5bb0c06e..f5d33e45 100644 --- a/src/uu/snice/src/snice.rs +++ b/src/uu/snice/src/snice.rs @@ -10,6 +10,7 @@ pub use action::ActionResult; use action::{perform_action, process_snapshot, users, SelectedTarget}; use clap::{crate_version, Arg, Command}; use prettytable::{format::consts::FORMAT_CLEAN, row, Table}; +pub use process_matcher::clap_args; use process_matcher::*; use sysinfo::Pid; use uu_pgrep::process::ProcessInformation;