mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-05 15:27:04 +00:00
fortune: Port to Core::Stream
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <stdio.h>
|
||||
@@ -75,19 +75,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio rpath"));
|
||||
|
||||
char const* path = "/res/fortunes.json";
|
||||
StringView path = "/res/fortunes.json"sv;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("Open a fortune cookie, receive a free quote for the day!");
|
||||
args_parser.add_positional_argument(path, "Path to JSON file with quotes (/res/fortunes.json by default)", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
|
||||
TRY(Core::System::unveil("/etc/timezone", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto file_contents = file->read_all();
|
||||
auto file_contents = TRY(file->read_all());
|
||||
auto json = TRY(JsonValue::from_string(file_contents));
|
||||
if (!json.is_array()) {
|
||||
warnln("{} does not contain an array of quotes", path);
|
||||
|
||||
Reference in New Issue
Block a user