Utilities: Add 'quiet' mode to grep

This commit is contained in:
Marco Cutecchia 2021-10-30 12:54:26 +02:00 committed by Ali Mohammad Pur
parent 0f91b22795
commit 647f89f15e
Notes: sideshowbarker 2024-07-18 01:43:36 +09:00

View file

@ -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 {