mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 19:45:10 +00:00
StateMachineGenerator: Pass output file as an argument
This allows us to avoid shell redirection to create output files, and will help with the GN build.
This commit is contained in:
parent
f87a488b22
commit
f8e1544f41
2 changed files with 11 additions and 5 deletions
|
@ -216,10 +216,15 @@ void output_header(StateMachine const&, SourceGenerator&);
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
StringView path;
|
||||
args_parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
|
||||
args_parser.parse(arguments);
|
||||
StringView output_file = "-"sv;
|
||||
|
||||
Core::ArgsParser parser;
|
||||
parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
|
||||
parser.add_option(output_file, "Place to write file", "output", 'o', "output-file");
|
||||
parser.parse(arguments);
|
||||
|
||||
auto output = TRY(Core::File::open_file_or_standard_stream(output_file, Core::File::OpenMode::Write));
|
||||
|
||||
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
|
||||
auto content = TRY(file->read_until_eof());
|
||||
|
@ -228,7 +233,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
output_header(*state_machine, generator);
|
||||
outln("{}", generator.as_string_view());
|
||||
|
||||
TRY(output->write_until_depleted(generator.as_string_view().bytes()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue