mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +00:00
errno: Port to LibMain
This commit is contained in:
parent
2e0f53c25d
commit
8aafe6cd1f
2 changed files with 8 additions and 6 deletions
|
@ -88,6 +88,7 @@ target_link_libraries(dmesg LibMain)
|
|||
target_link_libraries(du LibMain)
|
||||
target_link_libraries(echo LibMain)
|
||||
target_link_libraries(env LibMain)
|
||||
target_link_libraries(errno LibMain)
|
||||
target_link_libraries(expr LibRegex LibMain)
|
||||
target_link_libraries(fdtdump LibDeviceTree LibMain)
|
||||
target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
|
||||
|
|
|
@ -5,19 +5,20 @@
|
|||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
bool list = false;
|
||||
bool search = false;
|
||||
const char* keyword = nullptr;
|
||||
StringView keyword;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(keyword, "Error number or string to search", "keyword", Core::ArgsParser::Required::No);
|
||||
args_parser.add_option(list, "List all errno values", "list", 'l');
|
||||
args_parser.add_option(search, "Search for error descriptions containing keyword", "search", 's');
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (list) {
|
||||
for (int i = 0; i < sys_nerr; i++) {
|
||||
|
@ -26,7 +27,7 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (keyword == nullptr)
|
||||
if (keyword.is_empty())
|
||||
return 0;
|
||||
|
||||
if (search) {
|
||||
|
@ -39,14 +40,14 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
auto maybe_errno = StringView { keyword }.to_int();
|
||||
auto maybe_errno = keyword.to_int();
|
||||
if (!maybe_errno.has_value()) {
|
||||
warnln("ERROR: Not understood: {}", keyword);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto error = String::formatted("{}", strerror(maybe_errno.value()));
|
||||
if (error == "Unknown error") {
|
||||
if (error == "Unknown error"sv) {
|
||||
warnln("ERROR: Unknown errno: {}", keyword);
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue