diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 47f75c4f24..95e7aa9b78 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -482,7 +482,7 @@ if (BUILD_LAGOM) add_executable(gml-format_lagom ../../Userland/Utilities/gml-format.cpp) set_target_properties(gml-format_lagom PROPERTIES OUTPUT_NAME gml-format) - target_link_libraries(gml-format_lagom LagomCore LagomGML) + target_link_libraries(gml-format_lagom LagomCore LagomGML LagomMain) add_executable(js_lagom ../../Userland/Utilities/js.cpp) set_target_properties(js_lagom PROPERTIES OUTPUT_NAME js) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index a58211a98c..1012125e9c 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -99,7 +99,7 @@ target_link_libraries(find LibMain) target_link_libraries(flock LibMain) target_link_libraries(fortune LibMain) target_link_libraries(functrace LibDebug LibX86 LibMain) -target_link_libraries(gml-format LibGUI) +target_link_libraries(gml-format LibGUI LibMain) target_link_libraries(grep LibRegex) target_link_libraries(gron LibMain) target_link_libraries(groups LibMain) diff --git a/Userland/Utilities/gml-format.cpp b/Userland/Utilities/gml-format.cpp index bc7e53021b..951cf5bf29 100644 --- a/Userland/Utilities/gml-format.cpp +++ b/Userland/Utilities/gml-format.cpp @@ -6,12 +6,13 @@ #include #include +#include #include -#include +#include -bool format_file(StringView, bool); +ErrorOr format_file(StringView, bool); -bool format_file(StringView path, bool inplace) +ErrorOr format_file(StringView path, bool inplace) { auto read_from_stdin = path == "-"; RefPtr file; @@ -19,12 +20,7 @@ bool format_file(StringView path, bool inplace) file = Core::File::standard_input(); } else { auto open_mode = inplace ? Core::OpenMode::ReadWrite : Core::OpenMode::ReadOnly; - auto file_or_error = Core::File::open(path, open_mode); - if (file_or_error.is_error()) { - warnln("Could not open {}: {}", path, file_or_error.error()); - return false; - } - file = file_or_error.value(); + file = TRY(Core::File::open(path, open_mode)); } auto formatted_gml = GUI::format_gml(file->read_all()); if (formatted_gml.is_null()) { @@ -46,13 +42,10 @@ bool format_file(StringView path, bool inplace) return true; } -int main(int argc, char** argv) +ErrorOr serenity_main(Main::Arguments args) { #ifdef __serenity__ - if (pledge("stdio rpath wpath cpath", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio rpath wpath cpath", nullptr)); #endif bool inplace = false; @@ -62,15 +55,11 @@ int main(int argc, char** argv) args_parser.set_general_help("Format GML files."); args_parser.add_option(inplace, "Write formatted contents back to file rather than standard output", "inplace", 'i'); args_parser.add_positional_argument(files, "File(s) to process", "path", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(args); #ifdef __serenity__ - if (!inplace) { - if (pledge("stdio rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - } + if (!inplace) + TRY(Core::System::pledge("stdio rpath", nullptr)); #endif unsigned exit_code = 0; @@ -78,7 +67,7 @@ int main(int argc, char** argv) if (files.is_empty()) files.append("-"); for (auto& file : files) { - if (!format_file(file, inplace)) + if (!TRY(format_file(file, inplace))) exit_code = 1; }