From c46b6899b8cf71a8d70665ff7a483ebb39e6ea54 Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Tue, 23 Jul 2024 19:56:48 +0300 Subject: [PATCH] Add short arguments support --- src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 511af16..0d5659b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,12 +91,12 @@ fn main() -> ExitCode { } Mode::Help => { let lines = [ - "pkill => all unique processed, excl. system\n", - "pkill => filtered processes by name or it's part\n", - "pkill --all => all processes, incl. system\n", - "pkill --pid => PID of the first occurence\n", - "pkill --kill / => terminate process by its PID or name\n", - "pkill --help => print help\n", + "pkill => all unique processed, excl. system\n", + "pkill => filtered processes by name or it's part\n", + "pkill -a/--all => all processes, incl. system\n", + "pkill -p/--pid => PID of the first occurence\n", + "pkill -k1/--kill / => terminate process by its PID or name\n", + "pkill -h/--help => print help\n", ]; println!("{}", lines.concat()); ExitCode::SUCCESS @@ -109,18 +109,18 @@ fn parse_mode() -> Mode { let mut iter = env::args().skip(1).into_iter(); while let Some(el) = iter.next() { match el.as_str() { - "--help" => mode = Mode::Help, - "--all" => { + "-h" | "--help" => mode = Mode::Help, + "-a" | "--all" => { mode = Mode::All; } - "--pid" => { + "-p" | "--pid" => { if let Some(name) = iter.next() { mode = Mode::Single(name.to_ascii_lowercase()); } else { continue; } } - "--kill" => { + "-k1" | "--kill" => { if let Some(name) = iter.next() { mode = match name.parse() { Ok(pid) => Mode::TerminateByPid(pid),