diff options
author | Marco Cutecchia <marco.cutecchia@outlook.it> | 2021-10-30 13:04:12 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-10-31 14:18:29 +0330 |
commit | 0086466b61c11e25388358b4a2a20d9f069b6a20 (patch) | |
tree | 69540f97175d171f719ec74b6bc38c00bfada7bf /Userland/Utilities/grep.cpp | |
parent | 647f89f15ee39355241795a9b8bd116a82fbec91 (diff) | |
download | serenity-0086466b61c11e25388358b4a2a20d9f069b6a20.zip |
Utilities: Add option to suppress errors to grep
Diffstat (limited to 'Userland/Utilities/grep.cpp')
-rw-r--r-- | Userland/Utilities/grep.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index 6bb2f7abc9..e3a1a729e0 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -48,6 +48,7 @@ int main(int argc, char** argv) bool case_insensitive = false; bool invert_match = false; bool quiet_mode = false; + bool suppress_errors = false; bool colored_output = isatty(STDOUT_FILENO); Core::ArgsParser args_parser; @@ -57,6 +58,7 @@ int main(int argc, char** argv) 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(suppress_errors, "Suppress error messages for nonexistent or unreadable files", "no-messages", 's'); args_parser.add_option(Core::ArgsParser::Option { .requires_argument = true, .help_string = "Action to take for binary files ([binary], text, skip)", @@ -158,10 +160,11 @@ int main(int argc, char** argv) return false; }; - auto handle_file = [&matches, binary_mode](StringView filename, bool print_filename) -> bool { + auto handle_file = [&matches, binary_mode, suppress_errors](StringView filename, bool print_filename) -> bool { auto file = Core::File::construct(filename); if (!file->open(Core::OpenMode::ReadOnly)) { - warnln("Failed to open {}: {}", filename, file->error_string()); + if (!suppress_errors) + warnln("Failed to open {}: {}", filename, file->error_string()); return false; } |