libcruft-util/tools/json-validate.cpp

45 lines
957 B
C++
Raw Normal View History

2016-02-26 13:36:01 +11: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/.
2016-02-26 13:36:01 +11:00
*
* Copyright:
* 2014-2016, Danny Robson <danny@nerdcruft.net>
2016-02-26 13:36:01 +11:00
*/
#include "json/flat.hpp"
#include "json/except.hpp"
#include "io.hpp"
2012-04-12 14:14:33 +10:00
#include <iostream>
#include <cstdlib>
enum {
ARG_CMD,
ARG_PATH,
NUM_ARGS
};
int
main (int argc, char ** argv) {
if (argc != NUM_ARGS) {
std::cerr << "Invalid arguments. "
<< argv[ARG_CMD] << " <path> "
<< std::endl;
return EXIT_FAILURE;
}
try {
const cruft::mapped_file data (argv[ARG_PATH]);
json::flat::parse (cruft::view{data}.cast<const char*> ());
} catch (const json::error &x) {
std::cerr << "error: " << x.what () << '\n';
2012-04-12 14:14:33 +10:00
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}