2012-04-20 18:20:49 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-04-20 18:20:49 +10:00
|
|
|
*
|
2015-03-18 16:08:18 +11:00
|
|
|
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
2012-04-20 18:20:49 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-02-03 00:07:09 +11:00
|
|
|
#include "json/except.hpp"
|
2015-03-18 16:08:18 +11:00
|
|
|
#include "json/schema.hpp"
|
2016-10-11 23:47:57 +11:00
|
|
|
#include "json/tree.hpp"
|
2012-04-20 18:20:49 +10:00
|
|
|
|
2018-07-16 13:00:14 +10:00
|
|
|
#include "json/constraint/except.hpp"
|
2018-07-11 19:28:13 +10:00
|
|
|
|
2016-06-28 15:58:41 +10:00
|
|
|
#include "io.hpp"
|
|
|
|
|
2018-12-05 19:12:03 +11:00
|
|
|
#include <filesystem>
|
2016-08-04 17:42:41 +10:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-04-20 18:20:49 +10:00
|
|
|
|
2018-12-05 19:12:03 +11:00
|
|
|
namespace fs = std::filesystem;
|
2012-04-20 18:20:49 +10:00
|
|
|
|
2016-08-04 17:42:41 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-04-20 18:20:49 +10:00
|
|
|
enum {
|
2015-03-18 16:08:18 +11:00
|
|
|
ARG_CMD,
|
2012-04-20 18:20:49 +10:00
|
|
|
ARG_SCHEMA,
|
|
|
|
ARG_INPUT,
|
|
|
|
|
|
|
|
NUM_ARGS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-04 17:42:41 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-04-20 18:20:49 +10:00
|
|
|
int
|
|
|
|
main (int argc, char **argv) {
|
|
|
|
if (argc != NUM_ARGS) {
|
2015-03-18 16:08:18 +11:00
|
|
|
std::cerr << argv[ARG_CMD] << " <schema> <json>\n";
|
2012-04-20 18:20:49 +10:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-03-23 18:42:00 +11:00
|
|
|
try {
|
2018-08-05 14:42:02 +10:00
|
|
|
const cruft::mapped_file input_src (argv[ARG_INPUT]);
|
2016-06-28 15:58:41 +10:00
|
|
|
|
2018-07-11 19:28:13 +10:00
|
|
|
json::schema::validator schema (argv[ARG_SCHEMA]);
|
2018-08-05 14:42:02 +10:00
|
|
|
auto input = json::tree::parse (cruft::view{input_src} .cast<const char*>());
|
2016-04-27 17:09:48 +10:00
|
|
|
|
2018-07-11 19:28:13 +10:00
|
|
|
if (!schema.validate (*input)) {
|
|
|
|
std::cerr << "fail\n";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2018-06-22 14:09:23 +10:00
|
|
|
|
|
|
|
std::cout << *input << '\n';
|
2018-08-05 14:42:02 +10:00
|
|
|
} catch (cruft::json::schema::error const &x) {
|
2018-07-11 19:28:13 +10:00
|
|
|
std::cerr << "schema: " << x.what () << '\n';
|
|
|
|
return EXIT_FAILURE;
|
2015-03-23 18:42:00 +11:00
|
|
|
} catch (const json::error &e) {
|
|
|
|
std::cerr << "error: " << e.what () << '\n';
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2012-04-20 18:20:49 +10:00
|
|
|
}
|