Skip to content

Commit 209a2b3

Browse files
authored
Improve help output for config recipes (LLNL#534)
* Improve help output for config recipes * Fix test
1 parent 6fdea23 commit 209a2b3

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

src/caliper/ConfigManager.cpp

+13-21
Original file line numberDiff line numberDiff line change
@@ -1187,44 +1187,36 @@ struct ConfigManager::ConfigManagerImpl
11871187

11881188
std::string
11891189
get_documentation_for_spec(const char* name) const {
1190-
std::string doc(name);
1190+
std::ostringstream out;
1191+
out << name;
11911192

11921193
auto it = m_spec.find(name);
11931194
if (it == m_spec.end()) {
1194-
doc.append(": Not available");
1195+
out << ": Not available";
11951196
} else {
1196-
doc.append("\n ").append(it->second->description);
1197-
1197+
out << "\n " << it->second->description;
11981198
auto optdescrmap = options_for_config(*it->second).get_option_descriptions();
11991199

12001200
if (!optdescrmap.empty()) {
1201-
doc.append("\n Options:");
1201+
size_t len = 0;
1202+
for (const auto &op : optdescrmap)
1203+
len = std::max<size_t>(len, op.first.size());
1204+
1205+
out << "\n Options:";
12021206
for (const auto &op : optdescrmap)
1203-
doc.append("\n ").append(op.first).append("\n ").append(op.second);
1207+
util::pad_right(out << "\n ", op.first, len) << op.second;
12041208
}
12051209
}
12061210

1207-
return doc;
1211+
return out.str();
12081212
}
12091213

12101214
std::vector<std::string>
12111215
get_docstrings() const {
12121216
std::vector<std::string> ret;
12131217

1214-
for (const auto &p : m_spec) {
1215-
std::string doc = p.first;
1216-
doc.append("\n ").append(p.second->description);
1217-
1218-
auto optdescrmap = options_for_config(*p.second).get_option_descriptions();
1219-
1220-
if (!optdescrmap.empty()) {
1221-
doc.append("\n Options:");
1222-
for (const auto &op : optdescrmap)
1223-
doc.append("\n ").append(op.first).append("\n ").append(op.second);
1224-
}
1225-
1226-
ret.push_back(doc);
1227-
}
1218+
for (const auto &p : m_spec)
1219+
ret.push_back(get_documentation_for_spec(p.first.c_str()));
12281220

12291221
return ret;
12301222
}

src/caliper/test/test_configmanager.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ TEST(ConfigManagerTest, LoadCmd_ConfigAndOptions) {
466466
"testcontroller"
467467
"\n A test controller"
468468
"\n Options:"
469-
"\n testoption"
470-
"\n A test option";
469+
"\n testoption A test option";
471470

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

0 commit comments

Comments
 (0)