diff --git a/Userland/Utilities/gron.cpp b/Userland/Utilities/gron.cpp index 1008df60fc..0073da1ca1 100644 --- a/Userland/Utilities/gron.cpp +++ b/Userland/Utilities/gron.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -41,15 +42,25 @@ int main(int argc, char** argv) return 1; } - if (argc != 2 || !strcmp(argv[1], "--help")) { - warnln("usage: gron "); - warnln("Print each value in a JSON file with its fully expanded key."); - return argc != 2 ? 1 : 0; - } - auto file = Core::File::construct(argv[1]); - if (!file->open(Core::OpenMode::ReadOnly)) { - warnln("Failed to open {}: {}", file->name(), file->error_string()); - return 1; + Core::ArgsParser args_parser; + args_parser.set_general_help("Print each value in a JSON file with its fully expanded key."); + + const char* path = nullptr; + args_parser.add_positional_argument(path, "Input", "input", Core::ArgsParser::Required::No); + + args_parser.parse(argc, argv); + + RefPtr file; + + if (!path) { + file = Core::File::standard_input(); + } else { + auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly); + if (file_or_error.is_error()) { + warnln("Failed to open {}: {}", path, file_or_error.error()); + return 1; + } + file = file_or_error.value(); } if (pledge("stdio", nullptr) < 0) {