23main(
int argc,
char *argv[])
25 std::string output_file, db_name, classes, format(
"json");
26 bool direct_only(
false);
28 boost::program_options::options_description desc(
"Export conffwk schema using boost property tree.\n\nOptions/Arguments");
35 boost::program_options::value<std::string>(&db_name)->required(),
36 "database specification in format plugin-name:parameters"
40 boost::program_options::value<std::string>(&classes),
41 "regex defining class names; ignore if empty"
45 "print direct properties"
49 boost::program_options::value<std::string>(&output_file),
50 "output file name; print to standard out, if not defined"
54 boost::program_options::value<std::string>(&format)->default_value(format),
55 "output format (\"json\", \"xml\" or \"info\")"
62 boost::program_options::variables_map vm;
63 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
67 std::cout << desc << std::endl;
71 if (vm.count(
"direct-only"))
74 boost::program_options::notify(vm);
76 auto valid_formats = {
"json",
"xml",
"info"};
77 if (std::none_of(valid_formats.begin(), valid_formats.end(), [&format](
auto p){ return p == format; }))
78 throw std::runtime_error(
"unsupported format \"" + format +
'\"');
80 catch (std::exception& ex)
82 std::cerr <<
"command line error: " << ex.what() << std::endl;
90 boost::property_tree::ptree pt;
94 std::ostringstream buf;
96 boost::property_tree::json_parser::write_json(buf, pt);
97 else if (format ==
"xml")
98 boost::property_tree::xml_parser::write_xml(buf, pt, boost::property_tree::xml_writer_make_settings<std::string>(
' ', 4));
100 boost::property_tree::info_parser::write_info(buf, pt, boost::property_tree::info_writer_make_settings(
' ', 4));
102 if (!output_file.empty())
104 std::ofstream f(output_file);
105 f.exceptions(std::ifstream::failbit | std::ifstream::badbit);
110 std::cout << buf.str();
114 catch (
const dunedaq::conffwk::Exception &ex)
116 std::cout <<
"conffwk error: " << ex << std::endl;
118 catch (
const boost::property_tree::json_parser_error &ex)
120 std::cout <<
"ptree json error: " << ex.what() << std::endl;
122 catch (
const std::exception &ex)
124 std::cout <<
"error: " << ex.what() << std::endl;