16main(
int argc,
char *argv[])
18 std::string output_file, db_name, classes, format(
"json");
19 bool direct_only(
false);
21 boost::program_options::options_description desc(
"Export conffwk schema using boost property tree.\n\nOptions/Arguments");
28 boost::program_options::value<std::string>(&db_name)->required(),
29 "database specification in format plugin-name:parameters"
33 boost::program_options::value<std::string>(&classes),
34 "regex defining class names; ignore if empty"
38 "print direct properties"
42 boost::program_options::value<std::string>(&output_file),
43 "output file name; print to standard out, if not defined"
47 boost::program_options::value<std::string>(&format)->default_value(format),
48 "output format (\"json\", \"xml\" or \"info\")"
55 boost::program_options::variables_map vm;
56 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
60 std::cout << desc << std::endl;
64 if (vm.count(
"direct-only"))
67 boost::program_options::notify(vm);
69 auto valid_formats = {
"json",
"xml",
"info"};
70 if (std::none_of(valid_formats.begin(), valid_formats.end(), [&format](
auto p){ return p == format; }))
71 throw std::runtime_error(
"unsupported format \"" + format +
'\"');
73 catch (std::exception& ex)
75 std::cerr <<
"command line error: " << ex.what() << std::endl;
83 boost::property_tree::ptree pt;
87 std::ostringstream buf;
89 boost::property_tree::json_parser::write_json(buf, pt);
90 else if (format ==
"xml")
91 boost::property_tree::xml_parser::write_xml(buf, pt, boost::property_tree::xml_writer_make_settings<std::string>(
' ', 4));
93 boost::property_tree::info_parser::write_info(buf, pt, boost::property_tree::info_writer_make_settings(
' ', 4));
95 if (!output_file.empty())
97 std::ofstream f(output_file);
98 f.exceptions(std::ifstream::failbit | std::ifstream::badbit);
103 std::cout << buf.str();
107 catch (
const dunedaq::conffwk::Exception &ex)
109 std::cout <<
"conffwk error: " << ex << std::endl;
111 catch (
const boost::property_tree::json_parser_error &ex)
113 std::cout <<
"ptree json error: " << ex.what() << std::endl;
115 catch (
const std::exception &ex)
117 std::cout <<
"error: " << ex.what() << std::endl;