Add short arguments support
This commit is contained in:
parent
9583c22b2c
commit
c46b6899b8
20
src/main.rs
20
src/main.rs
@ -91,12 +91,12 @@ fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
Mode::Help => {
|
Mode::Help => {
|
||||||
let lines = [
|
let lines = [
|
||||||
"pkill => all unique processed, excl. system\n",
|
"pkill => all unique processed, excl. system\n",
|
||||||
"pkill <name> => filtered processes by name or it's part\n",
|
"pkill <name> => filtered processes by name or it's part\n",
|
||||||
"pkill --all => all processes, incl. system\n",
|
"pkill -a/--all => all processes, incl. system\n",
|
||||||
"pkill --pid <name> => PID of the first occurence\n",
|
"pkill -p/--pid <name> => PID of the first occurence\n",
|
||||||
"pkill --kill <PID>/<name> => terminate process by its PID or name\n",
|
"pkill -k1/--kill <PID>/<name> => terminate process by its PID or name\n",
|
||||||
"pkill --help => print help\n",
|
"pkill -h/--help => print help\n",
|
||||||
];
|
];
|
||||||
println!("{}", lines.concat());
|
println!("{}", lines.concat());
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
@ -109,18 +109,18 @@ fn parse_mode() -> Mode {
|
|||||||
let mut iter = env::args().skip(1).into_iter();
|
let mut iter = env::args().skip(1).into_iter();
|
||||||
while let Some(el) = iter.next() {
|
while let Some(el) = iter.next() {
|
||||||
match el.as_str() {
|
match el.as_str() {
|
||||||
"--help" => mode = Mode::Help,
|
"-h" | "--help" => mode = Mode::Help,
|
||||||
"--all" => {
|
"-a" | "--all" => {
|
||||||
mode = Mode::All;
|
mode = Mode::All;
|
||||||
}
|
}
|
||||||
"--pid" => {
|
"-p" | "--pid" => {
|
||||||
if let Some(name) = iter.next() {
|
if let Some(name) = iter.next() {
|
||||||
mode = Mode::Single(name.to_ascii_lowercase());
|
mode = Mode::Single(name.to_ascii_lowercase());
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"--kill" => {
|
"-k1" | "--kill" => {
|
||||||
if let Some(name) = iter.next() {
|
if let Some(name) = iter.next() {
|
||||||
mode = match name.parse() {
|
mode = match name.parse() {
|
||||||
Ok(pid) => Mode::TerminateByPid(pid),
|
Ok(pid) => Mode::TerminateByPid(pid),
|
||||||
|
Loading…
Reference in New Issue
Block a user