From 23fb3946c7f4c0702b1b168e1d78b8b62597e3f1 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Mon, 8 Aug 2022 15:28:34 -0500 Subject: [PATCH] Handle --advanced printing for config generation (#137) Handle --advanced printing for config --- .../bin/omnitrace-avail/generate_config.cpp | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/source/bin/omnitrace-avail/generate_config.cpp b/source/bin/omnitrace-avail/generate_config.cpp index ea5b7f91..10ae88a8 100644 --- a/source/bin/omnitrace-avail/generate_config.cpp +++ b/source/bin/omnitrace-avail/generate_config.cpp @@ -82,7 +82,7 @@ ignore_setting(const Tp& _v) category_view.count("settings::deprecated") == 0 && _v->get_categories().count("deprecated") > 0) return true; - if(category_view.count("advanced") == 0 && + if(!print_advanced && category_view.count("advanced") == 0 && category_view.count("settings::advanced") == 0 && _v->get_categories().count("advanced") > 0) return true; @@ -209,17 +209,28 @@ generate_config(std::string _config_file, const std::set& _config_f } _output_dir += "/"; + auto _fmts = std::set{}; std::string _txt_ext = ".cfg"; for(std::string itr : { ".cfg", ".txt", ".json", ".xml" }) { + if(_config_file.length() <= itr.length()) continue; auto _pos = _config_file.rfind(itr); if(_pos == _config_file.length() - itr.length()) { if(itr == ".cfg" || itr == ".txt") _txt_ext = itr; + _fmts.emplace(itr.substr(1)); _config_file = _config_file.substr(0, _pos); } } + if(_fmts.empty() && _config_fmts.size() == 1) + _fmts = _config_fmts; + else if(!_fmts.empty()) + { + for(auto& itr : _config_fmts) + _fmts.emplace(itr); + } + update_choices(_settings); using json_t = cereal::PrettyJSONOutputArchive; @@ -239,8 +250,10 @@ generate_config(std::string _config_file, const std::set& _config_f _ar->finishNode(); }; - auto _open = [](std::ofstream& _ofs, const std::string& _fname, - const std::string& _type) -> std::ofstream& { + auto _nout = 0; + auto _open = [&_nout](std::ofstream& _ofs, const std::string& _fname, + const std::string& _type) -> std::ofstream& { + ++_nout; if(file_exists(_fname)) { if(force_config) @@ -273,7 +286,7 @@ generate_config(std::string _config_file, const std::set& _config_f return _ofs; }; - if(_config_fmts.count("json") > 0) + if(_fmts.count("json") > 0) { std::stringstream _ss{}; output_archive::indent_length() = 4; @@ -284,7 +297,7 @@ generate_config(std::string _config_file, const std::set& _config_f _open(ofs, _fname, "JSON") << _ss.str() << "\n"; } - if(_config_fmts.count("xml") > 0) + if(_fmts.count("xml") > 0) { std::stringstream _ss{}; output_archive::indent() = true; @@ -295,7 +308,7 @@ generate_config(std::string _config_file, const std::set& _config_f _open(ofs, _fname, "XML") << _ss.str() << "\n"; } - if(_config_fmts.count("txt") > 0) + if(_fmts.count("txt") > 0 || _fmts.count("cfg") > 0 || _nout == 0) { std::stringstream _ss{}; size_t _w = min_width;