Implement CLI
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
This commit is contained in:
parent
4e4c192c87
commit
8f2e050c5c
22
src/cli.cpp
22
src/cli.cpp
@ -1,17 +1,39 @@
|
|||||||
#include <CLI/App.hpp>
|
#include <CLI/App.hpp>
|
||||||
#include <CLI/Config.hpp>
|
#include <CLI/Config.hpp>
|
||||||
#include <CLI/Formatter.hpp>
|
#include <CLI/Formatter.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "nlohmann/json-schema.hpp"
|
||||||
|
|
||||||
|
using namespace nlohmann;
|
||||||
|
using namespace nlohmann::json_schema;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
std::ifstream schema_input;
|
||||||
|
std::ifstream object_input;
|
||||||
|
|
||||||
CLI::App app{"Json schema validator", "json-validator"};
|
CLI::App app{"Json schema validator", "json-validator"};
|
||||||
// TODO: Move to a generated header file
|
// TODO: Move to a generated header file
|
||||||
app.set_version_flag("--version", "2.2.0");
|
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 {
|
try {
|
||||||
app.parse(argc, argv);
|
app.parse(argc, argv);
|
||||||
} catch (const CLI::ParseError &e) {
|
} catch (const CLI::ParseError &e) {
|
||||||
return app.exit(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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user