Skip to content

Commit 8f2e050

Browse files
committed
Implement CLI
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
1 parent 4e4c192 commit 8f2e050

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/cli.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
#include <CLI/App.hpp>
22
#include <CLI/Config.hpp>
33
#include <CLI/Formatter.hpp>
4+
#include <fstream>
5+
6+
#include "nlohmann/json-schema.hpp"
7+
8+
using namespace nlohmann;
9+
using namespace nlohmann::json_schema;
410

511
int main(int argc, char *argv[])
612
{
13+
std::ifstream schema_input;
14+
std::ifstream object_input;
15+
716
CLI::App app{"Json schema validator", "json-validator"};
817
// TODO: Move to a generated header file
918
app.set_version_flag("--version", "2.2.0");
19+
app.add_option("schema", schema_input, "JSON schema of the object")
20+
->check(CLI::ExistingFile);
21+
app.add_option("object", "JSON object to validate")
22+
->check(CLI::ExistingFile);
1023

1124
try {
1225
app.parse(argc, argv);
1326
} catch (const CLI::ParseError &e) {
1427
return app.exit(e);
1528
}
29+
30+
json schema{};
31+
json object{};
32+
if (!schema_input.good())
33+
throw std::invalid_argument("could not read schema");
34+
if (!object_input.good())
35+
throw std::invalid_argument("could not read object");
36+
schema_input >> schema;
37+
object_input >> object;
1638
return 0;
1739
}

0 commit comments

Comments
 (0)