Use relative path

Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
This commit is contained in:
Cristian Le 2023-05-10 18:18:13 +02:00
parent f543f18d13
commit 60603f6c8d
Failed to extract signature

View File

@ -11,16 +11,16 @@ using namespace nlohmann::json_schema;
class main_cli : public CLI::App class main_cli : public CLI::App
{ {
std::ifstream schema_input; std::ifstream schema_input;
std::ifstream object_input; std::filesystem::path object_path;
// TODO: Export this as a built-in loader // TODO: Export this as a built-in loader
static void loader(const json_uri &uri, json &schema) void loader(const json_uri &uri, json &sch)
{ {
std::string filename = "./" + uri.path(); std::string filename = object_path.parent_path().append(uri.path());
std::ifstream lf(filename); std::ifstream lf(filename);
if (!lf.good()) if (!lf.good())
throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename); throw std::invalid_argument("could not open " + uri.url() + " tried with " + filename);
try { try {
lf >> schema; lf >> sch;
} catch (const std::exception &e) { } catch (const std::exception &e) {
throw e; throw e;
} }
@ -32,13 +32,15 @@ public:
json_validator validator; json_validator validator;
main_cli() main_cli()
: CLI::App{"Json schema validator", "json-validator"}, : CLI::App{"Json schema validator", "json-validator"},
validator{loader, default_string_format_check} validator{
[this](const json_uri &u, json &s) { this->loader(u, s); },
default_string_format_check}
{ {
// TODO: Move to a generated header file // TODO: Move to a generated header file
set_version_flag("--version", "2.2.0"); set_version_flag("--version", "2.2.0");
add_option("schema", schema_input, "JSON schema of the object") add_option("schema", schema_input, "JSON schema of the object")
->check(CLI::ExistingFile); ->check(CLI::ExistingFile);
add_option("object", object_input, "JSON object to validate") add_option("object", object_path, "JSON object to validate")
->check(CLI::ExistingFile); ->check(CLI::ExistingFile);
} }
void validate() void validate()