diff options
author | Marco Cutecchia <marco.cutecchia@outlook.it> | 2021-10-30 12:54:26 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-10-31 14:18:29 +0330 |
commit | 647f89f15ee39355241795a9b8bd116a82fbec91 (patch) | |
tree | a0a07db23c12c0fe12403fac74a38f15e4a757e6 /Userland/Utilities/grep.cpp | |
parent | 0f91b22795d37aead9ded51347cb367adede7dfd (diff) | |
download | serenity-647f89f15ee39355241795a9b8bd116a82fbec91.zip |
Utilities: Add 'quiet' mode to grep
Diffstat (limited to 'Userland/Utilities/grep.cpp')
-rw-r--r-- | Userland/Utilities/grep.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index 5e352053a5..6bb2f7abc9 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -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 { |