From f4f3ab0ad9fd58de37be7eb622dd4483e5320f1f Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 5 Aug 2020 21:13:25 +0200 Subject: [PATCH] Userland: Use Core::ArgsParser for 'jp' --- Userland/jp.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Userland/jp.cpp b/Userland/jp.cpp index 436eb97d2b..28823a23be 100644 --- a/Userland/jp.cpp +++ b/Userland/jp.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -46,13 +47,15 @@ int main(int argc, char** argv) return 1; } - if (argc != 2) { - fprintf(stderr, "usage: jp \n"); - return 0; - } - auto file = Core::File::construct(argv[1]); + const char* path = nullptr; + + Core::ArgsParser args_parser; + args_parser.add_positional_argument(path, "Path to JSON file", "path"); + args_parser.parse(argc, argv); + + auto file = Core::File::construct(path); if (!file->open(Core::IODevice::ReadOnly)) { - fprintf(stderr, "Couldn't open %s for reading: %s\n", argv[1], file->error_string()); + fprintf(stderr, "Couldn't open %s for reading: %s\n", path, file->error_string()); return 1; }