mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:57:44 +00:00
Utilities: Add option to suppress errors to grep
This commit is contained in:
parent
647f89f15e
commit
0086466b61
1 changed files with 5 additions and 2 deletions
|
@ -48,6 +48,7 @@ int main(int argc, char** argv)
|
||||||
bool case_insensitive = false;
|
bool case_insensitive = false;
|
||||||
bool invert_match = false;
|
bool invert_match = false;
|
||||||
bool quiet_mode = false;
|
bool quiet_mode = false;
|
||||||
|
bool suppress_errors = false;
|
||||||
bool colored_output = isatty(STDOUT_FILENO);
|
bool colored_output = isatty(STDOUT_FILENO);
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
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(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(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(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 {
|
args_parser.add_option(Core::ArgsParser::Option {
|
||||||
.requires_argument = true,
|
.requires_argument = true,
|
||||||
.help_string = "Action to take for binary files ([binary], text, skip)",
|
.help_string = "Action to take for binary files ([binary], text, skip)",
|
||||||
|
@ -158,10 +160,11 @@ int main(int argc, char** argv)
|
||||||
return false;
|
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);
|
auto file = Core::File::construct(filename);
|
||||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue