Skip to content

Commit 23fb394

Browse files
authored
Handle --advanced printing for config generation (#137)
Handle --advanced printing for config
1 parent 040da3f commit 23fb394

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

source/bin/omnitrace-avail/generate_config.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ignore_setting(const Tp& _v)
8282
category_view.count("settings::deprecated") == 0 &&
8383
_v->get_categories().count("deprecated") > 0)
8484
return true;
85-
if(category_view.count("advanced") == 0 &&
85+
if(!print_advanced && category_view.count("advanced") == 0 &&
8686
category_view.count("settings::advanced") == 0 &&
8787
_v->get_categories().count("advanced") > 0)
8888
return true;
@@ -209,17 +209,28 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
209209
}
210210
_output_dir += "/";
211211

212+
auto _fmts = std::set<std::string>{};
212213
std::string _txt_ext = ".cfg";
213214
for(std::string itr : { ".cfg", ".txt", ".json", ".xml" })
214215
{
216+
if(_config_file.length() <= itr.length()) continue;
215217
auto _pos = _config_file.rfind(itr);
216218
if(_pos == _config_file.length() - itr.length())
217219
{
218220
if(itr == ".cfg" || itr == ".txt") _txt_ext = itr;
221+
_fmts.emplace(itr.substr(1));
219222
_config_file = _config_file.substr(0, _pos);
220223
}
221224
}
222225

226+
if(_fmts.empty() && _config_fmts.size() == 1)
227+
_fmts = _config_fmts;
228+
else if(!_fmts.empty())
229+
{
230+
for(auto& itr : _config_fmts)
231+
_fmts.emplace(itr);
232+
}
233+
223234
update_choices(_settings);
224235

225236
using json_t = cereal::PrettyJSONOutputArchive;
@@ -239,8 +250,10 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
239250
_ar->finishNode();
240251
};
241252

242-
auto _open = [](std::ofstream& _ofs, const std::string& _fname,
243-
const std::string& _type) -> std::ofstream& {
253+
auto _nout = 0;
254+
auto _open = [&_nout](std::ofstream& _ofs, const std::string& _fname,
255+
const std::string& _type) -> std::ofstream& {
256+
++_nout;
244257
if(file_exists(_fname))
245258
{
246259
if(force_config)
@@ -273,7 +286,7 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
273286
return _ofs;
274287
};
275288

276-
if(_config_fmts.count("json") > 0)
289+
if(_fmts.count("json") > 0)
277290
{
278291
std::stringstream _ss{};
279292
output_archive<cereal::PrettyJSONOutputArchive>::indent_length() = 4;
@@ -284,7 +297,7 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
284297
_open(ofs, _fname, "JSON") << _ss.str() << "\n";
285298
}
286299

287-
if(_config_fmts.count("xml") > 0)
300+
if(_fmts.count("xml") > 0)
288301
{
289302
std::stringstream _ss{};
290303
output_archive<cereal::XMLOutputArchive>::indent() = true;
@@ -295,7 +308,7 @@ generate_config(std::string _config_file, const std::set<std::string>& _config_f
295308
_open(ofs, _fname, "XML") << _ss.str() << "\n";
296309
}
297310

298-
if(_config_fmts.count("txt") > 0)
311+
if(_fmts.count("txt") > 0 || _fmts.count("cfg") > 0 || _nout == 0)
299312
{
300313
std::stringstream _ss{};
301314
size_t _w = min_width;

0 commit comments

Comments
 (0)