Add simple json reformatter utility
This commit is contained in:
parent
e44e629ba7
commit
4ab352036d
10
Makefile.am
10
Makefile.am
@ -102,3 +102,13 @@ lib_LTLIBRARIES = libutil.la
|
||||
libutil_la_SOURCES = $(UTIL_FILES)
|
||||
libutil_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
libutil_la_LIBADD = $(BOOST_SYSTEM_LIB)
|
||||
|
||||
bin_PROGRAMS = \
|
||||
json-clean
|
||||
|
||||
json_clean_SOURCES = json/clean.cpp
|
||||
json_clean_DEPENDENCIES = $(top_builddir)/.libs/libutil.la
|
||||
json_clean_LDFLAGS = \
|
||||
$(BOOST_LDFLAGS) \
|
||||
$(BOOST_FILESYSTEM_LIB) \
|
||||
$(top_builddir)/.libs/libutil.a
|
||||
|
39
json/clean.cpp
Normal file
39
json/clean.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "../json.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
enum {
|
||||
ARG_COMMAND,
|
||||
ARG_INPUT,
|
||||
|
||||
NUM_ARGS
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
print_usage (int argc, char **argv) {
|
||||
(void)argc;
|
||||
std::cerr << "usage: " << argv[0] << " <input>\n";
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv) {
|
||||
if (argc != NUM_ARGS) {
|
||||
print_usage (argc, argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
boost::filesystem::path input (argv[ARG_INPUT]);
|
||||
std::cout << *json::parse (input) << "\n";
|
||||
} catch (const json::error& err) {
|
||||
std::cerr << err.what () << "\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user