summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-08-05 21:13:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-06 20:41:13 +0200
commitf4f3ab0ad9fd58de37be7eb622dd4483e5320f1f (patch)
tree60cdc4af31e353b1b398895c98198e86ec1e7dd8 /Userland
parentab1f3551cca414cefc3c4e14bbe0cd2fc21fff97 (diff)
downloadserenity-f4f3ab0ad9fd58de37be7eb622dd4483e5320f1f.zip
Userland: Use Core::ArgsParser for 'jp'
Diffstat (limited to 'Userland')
-rw-r--r--Userland/jp.cpp15
1 files 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 <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/StringBuilder.h>
+#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <stdio.h>
#include <unistd.h>
@@ -46,13 +47,15 @@ int main(int argc, char** argv)
return 1;
}
- if (argc != 2) {
- fprintf(stderr, "usage: jp <file>\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;
}