summaryrefslogtreecommitdiff
path: root/Meta/Lagom/Tools
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-12 16:12:50 +0100
committerTim Flynn <trflynn89@pm.me>2022-09-20 07:48:45 -0400
commit684c3efc04711d4b352f0e10dd9543c61acc7a16 (patch)
treee781bcb977a03a00ec41d6044d260c4a1ef4b6c8 /Meta/Lagom/Tools
parentcb45fa79ee732733839758ddc597c896dfe86899 (diff)
downloadserenity-684c3efc04711d4b352f0e10dd9543c61acc7a16.zip
StateMachineGenerator: Port to LibMain and Core::Stream
Diffstat (limited to 'Meta/Lagom/Tools')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/CMakeLists.txt2
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/main.cpp17
2 files changed, 8 insertions, 11 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/CMakeLists.txt
index 98fafd84cc..7b02a71de0 100644
--- a/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/CMakeLists.txt
+++ b/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/CMakeLists.txt
@@ -2,4 +2,4 @@ set(SOURCES
main.cpp
)
-lagom_tool(StateMachineGenerator)
+lagom_tool(StateMachineGenerator LIBS LibMain)
diff --git a/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/main.cpp b/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/main.cpp
index 6651764d0e..c7609d2abe 100644
--- a/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/main.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/StateMachineGenerator/main.cpp
@@ -12,7 +12,8 @@
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <LibCore/ArgsParser.h>
-#include <LibCore/File.h>
+#include <LibCore/Stream.h>
+#include <LibMain/Main.h>
#include <ctype.h>
struct Range {
@@ -213,19 +214,15 @@ parse_state_machine(StringView input)
void output_header(StateMachine const&, SourceGenerator&);
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
Core::ArgsParser args_parser;
- char const* path = nullptr;
+ StringView path;
args_parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
- args_parser.parse(argc, argv);
+ args_parser.parse(arguments);
- auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
- if (file_or_error.is_error()) {
- fprintf(stderr, "Cannot open %s\n", path);
- }
-
- auto content = file_or_error.value()->read_all();
+ auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
+ auto content = TRY(file->read_all());
auto state_machine = parse_state_machine(content);
StringBuilder builder;