mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
fortune: Port to Core::Stream
This commit is contained in:
parent
813fc10aae
commit
d39552a7b7
1 changed files with 4 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue