2012-04-20 18:20:49 +10:00
|
|
|
/*
|
|
|
|
* This file is part of libgim.
|
|
|
|
*
|
|
|
|
* libgim is free software: you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
2015-02-02 23:00:38 +11:00
|
|
|
*
|
2012-04-20 18:20:49 +10:00
|
|
|
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
2015-02-02 23:00:38 +11:00
|
|
|
*
|
2012-04-20 18:20:49 +10:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
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"
|
|
|
|
#include "json/tree.hpp"
|
2015-03-18 16:08:18 +11:00
|
|
|
#include "json/schema.hpp"
|
2015-03-23 18:42:00 +11:00
|
|
|
#include "json/except.hpp"
|
2012-04-20 18:20:49 +10:00
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2015-03-18 16:08:18 +11:00
|
|
|
namespace fs = boost::filesystem;
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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-18 16:08:18 +11:00
|
|
|
auto schema = json::tree::parse (fs::path (argv[ARG_SCHEMA]));
|
|
|
|
auto input = json::tree::parse (fs::path (argv[ARG_INPUT]));
|
2015-02-02 23:00:38 +11:00
|
|
|
|
2015-03-23 18:42:00 +11:00
|
|
|
try {
|
|
|
|
json::schema::validate (*input, schema->as_object ());
|
|
|
|
} 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
|
|
|
}
|