mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
Userland: Use Core::ArgsParser for 'jp'
This commit is contained in:
parent
ab1f3551cc
commit
f4f3ab0ad9
1 changed files with 9 additions and 6 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -46,13 +47,15 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
const char* path = nullptr;
|
||||||
fprintf(stderr, "usage: jp <file>\n");
|
|
||||||
return 0;
|
Core::ArgsParser args_parser;
|
||||||
}
|
args_parser.add_positional_argument(path, "Path to JSON file", "path");
|
||||||
auto file = Core::File::construct(argv[1]);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
auto file = Core::File::construct(path);
|
||||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue