From 8f2e050c5c52a3da8ff3d13d8cd7c15aa2082e7b Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 10 May 2023 14:20:51 +0200 Subject: [PATCH] Implement CLI Signed-off-by: Cristian Le --- src/cli.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cli.cpp b/src/cli.cpp index 94519eb..e1af222 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -1,17 +1,39 @@ #include #include #include +#include + +#include "nlohmann/json-schema.hpp" + +using namespace nlohmann; +using namespace nlohmann::json_schema; int main(int argc, char *argv[]) { + std::ifstream schema_input; + std::ifstream object_input; + CLI::App app{"Json schema validator", "json-validator"}; // TODO: Move to a generated header file app.set_version_flag("--version", "2.2.0"); + app.add_option("schema", schema_input, "JSON schema of the object") + ->check(CLI::ExistingFile); + app.add_option("object", "JSON object to validate") + ->check(CLI::ExistingFile); try { app.parse(argc, argv); } catch (const CLI::ParseError &e) { return app.exit(e); } + + json schema{}; + json object{}; + if (!schema_input.good()) + throw std::invalid_argument("could not read schema"); + if (!object_input.good()) + throw std::invalid_argument("could not read object"); + schema_input >> schema; + object_input >> object; return 0; }