Skip to content

Commit

Permalink
Improve help output for config recipes (#534)
Browse files Browse the repository at this point in the history
* Improve help output for config recipes

* Fix test
  • Loading branch information
daboehme authored Feb 13, 2024
1 parent 6fdea23 commit 209a2b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
34 changes: 13 additions & 21 deletions src/caliper/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,44 +1187,36 @@ struct ConfigManager::ConfigManagerImpl

std::string
get_documentation_for_spec(const char* name) const {
std::string doc(name);
std::ostringstream out;
out << name;

auto it = m_spec.find(name);
if (it == m_spec.end()) {
doc.append(": Not available");
out << ": Not available";
} else {
doc.append("\n ").append(it->second->description);

out << "\n " << it->second->description;
auto optdescrmap = options_for_config(*it->second).get_option_descriptions();

if (!optdescrmap.empty()) {
doc.append("\n Options:");
size_t len = 0;
for (const auto &op : optdescrmap)
len = std::max<size_t>(len, op.first.size());

out << "\n Options:";
for (const auto &op : optdescrmap)
doc.append("\n ").append(op.first).append("\n ").append(op.second);
util::pad_right(out << "\n ", op.first, len) << op.second;
}
}

return doc;
return out.str();
}

std::vector<std::string>
get_docstrings() const {
std::vector<std::string> ret;

for (const auto &p : m_spec) {
std::string doc = p.first;
doc.append("\n ").append(p.second->description);

auto optdescrmap = options_for_config(*p.second).get_option_descriptions();

if (!optdescrmap.empty()) {
doc.append("\n Options:");
for (const auto &op : optdescrmap)
doc.append("\n ").append(op.first).append("\n ").append(op.second);
}

ret.push_back(doc);
}
for (const auto &p : m_spec)
ret.push_back(get_documentation_for_spec(p.first.c_str()));

return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions src/caliper/test/test_configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ TEST(ConfigManagerTest, LoadCmd_ConfigAndOptions) {
"testcontroller"
"\n A test controller"
"\n Options:"
"\n testoption"
"\n A test option";
"\n testoption A test option";

EXPECT_EQ(mgr.get_documentation_for_spec("testcontroller"), expect);
}

0 comments on commit 209a2b3

Please sign in to comment.