mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Utilities: Add 'quiet' mode to grep
This commit is contained in:
parent
0f91b22795
commit
647f89f15e
Notes:
sideshowbarker
2024-07-18 01:43:36 +09:00
Author: https://github.com/mrkct Commit: https://github.com/SerenityOS/serenity/commit/647f89f15ee Pull-request: https://github.com/SerenityOS/serenity/pull/10703
1 changed files with 5 additions and 0 deletions
|
@ -47,6 +47,7 @@ int main(int argc, char** argv)
|
|||
BinaryFileMode binary_mode { BinaryFileMode::Binary };
|
||||
bool case_insensitive = false;
|
||||
bool invert_match = false;
|
||||
bool quiet_mode = false;
|
||||
bool colored_output = isatty(STDOUT_FILENO);
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
|
@ -55,6 +56,7 @@ int main(int argc, char** argv)
|
|||
args_parser.add_option(pattern, "Pattern", "regexp", 'e', "Pattern");
|
||||
args_parser.add_option(case_insensitive, "Make matches case-insensitive", nullptr, 'i');
|
||||
args_parser.add_option(invert_match, "Select non-matching lines", "invert-match", 'v');
|
||||
args_parser.add_option(quiet_mode, "Do not write anything to standard output", "quiet", 'q');
|
||||
args_parser.add_option(Core::ArgsParser::Option {
|
||||
.requires_argument = true,
|
||||
.help_string = "Action to take for binary files ([binary], text, skip)",
|
||||
|
@ -132,6 +134,9 @@ int main(int argc, char** argv)
|
|||
|
||||
auto result = re.match(str, PosixFlags::Global);
|
||||
if (result.success ^ invert_match) {
|
||||
if (quiet_mode)
|
||||
return true;
|
||||
|
||||
if (is_binary && binary_mode == BinaryFileMode::Binary) {
|
||||
outln(colored_output ? "binary file \x1B[34m{}\x1B[0m matches" : "binary file {} matches", filename);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue