Add short arguments support

This commit is contained in:
aNNiMON 2024-07-23 19:56:48 +03:00
parent 9583c22b2c
commit c46b6899b8

View File

@ -93,10 +93,10 @@ fn main() -> ExitCode {
let lines = [
"pkill => all unique processed, excl. system\n",
"pkill <name> => filtered processes by name or it's part\n",
"pkill --all => all processes, incl. system\n",
"pkill --pid <name> => PID of the first occurence\n",
"pkill --kill <PID>/<name> => terminate process by its PID or name\n",
"pkill --help => print help\n",
"pkill -a/--all => all processes, incl. system\n",
"pkill -p/--pid <name> => PID of the first occurence\n",
"pkill -k1/--kill <PID>/<name> => 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),