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 => {
|
||||
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 => all unique processed, excl. system\n",
|
||||
"pkill <name> => filtered processes by name or it's part\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),
|
||||
|
Loading…
Reference in New Issue
Block a user