mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
pidof: Add -S option to specify a pid separator
This is useful for commands which expect a comma-separated list of pids.
This commit is contained in:
parent
8be7b16c42
commit
fac6c6c554
1 changed files with 7 additions and 1 deletions
|
@ -17,6 +17,7 @@ struct Options {
|
||||||
bool single_shot { false };
|
bool single_shot { false };
|
||||||
Optional<pid_t> pid_to_omit;
|
Optional<pid_t> pid_to_omit;
|
||||||
StringView process_name;
|
StringView process_name;
|
||||||
|
StringView pid_separator { " "sv };
|
||||||
};
|
};
|
||||||
|
|
||||||
static ErrorOr<int> pid_of(Options const& options)
|
static ErrorOr<int> pid_of(Options const& options)
|
||||||
|
@ -29,7 +30,11 @@ static ErrorOr<int> pid_of(Options const& options)
|
||||||
if (it.name != options.process_name || options.pid_to_omit == it.pid)
|
if (it.name != options.process_name || options.pid_to_omit == it.pid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
out(displayed_at_least_one ? " {}"sv : "{}"sv, it.pid);
|
if (displayed_at_least_one)
|
||||||
|
out("{}{}"sv, options.pid_separator, it.pid);
|
||||||
|
else
|
||||||
|
out("{}"sv, it.pid);
|
||||||
|
|
||||||
displayed_at_least_one = true;
|
displayed_at_least_one = true;
|
||||||
|
|
||||||
if (options.single_shot)
|
if (options.single_shot)
|
||||||
|
@ -75,6 +80,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
args_parser.add_option(options.single_shot, "Only return one pid", nullptr, 's');
|
args_parser.add_option(options.single_shot, "Only return one pid", nullptr, 's');
|
||||||
|
args_parser.add_option(options.pid_separator, "Use `separator` to separate multiple pids", nullptr, 'S', "separator");
|
||||||
args_parser.add_positional_argument(options.process_name, "Process name to search for", "process-name");
|
args_parser.add_positional_argument(options.process_name, "Process name to search for", "process-name");
|
||||||
|
|
||||||
args_parser.parse(args);
|
args_parser.parse(args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue