@@ -11,16 +11,16 @@ using namespace nlohmann::json_schema;
1111class main_cli : public CLI ::App
1212{
1313 std::ifstream schema_input;
14- std::ifstream object_input ;
14+ std::filesystem::path object_path ;
1515 // TODO: Export this as a built-in loader
16- static void loader (const json_uri &uri, json &schema )
16+ void loader (const json_uri &uri, json &sch )
1717 {
18- std::string filename = " ./ " + uri.path ();
18+ std::string filename = object_path. parent_path (). append ( uri.path () );
1919 std::ifstream lf (filename);
2020 if (!lf.good ())
2121 throw std::invalid_argument (" could not open " + uri.url () + " tried with " + filename);
2222 try {
23- lf >> schema ;
23+ lf >> sch ;
2424 } catch (const std::exception &e) {
2525 throw e;
2626 }
@@ -32,13 +32,15 @@ class main_cli : public CLI::App
3232 json_validator validator;
3333 main_cli ()
3434 : CLI::App{" Json schema validator" , " json-validator" },
35- validator{loader, default_string_format_check}
35+ validator{
36+ [this ](const json_uri &u, json &s) { this ->loader (u, s); },
37+ default_string_format_check}
3638 {
3739 // TODO: Move to a generated header file
3840 set_version_flag (" --version" , " 2.2.0" );
3941 add_option (" schema" , schema_input, " JSON schema of the object" )
4042 ->check (CLI::ExistingFile);
41- add_option (" object" , object_input , " JSON object to validate" )
43+ add_option (" object" , object_path , " JSON object to validate" )
4244 ->check (CLI::ExistingFile);
4345 }
4446 void validate ()
0 commit comments