Write a formatted description of arguments to an output stream. Write a list of the names and descriptions of arguments suitable for display as help information. \param out Stream to which output should be written. \param indent Number of characters to indent all text. \param totalWidth Total width to assume for formatting output. Typically this is the wi
| 1342 | Typically this is the width of a terminal window. |
| 1343 | */ |
| 1344 | void dump(std::ostream& out, size_t indent, size_t totalWidth) const |
| 1345 | { |
| 1346 | size_t namelen = 0; |
| 1347 | std::vector<std::pair<std::string, std::string>> info; |
| 1348 | |
| 1349 | for (auto ai = m_args.begin(); ai != m_args.end(); ++ai) |
| 1350 | { |
| 1351 | Arg *a = ai->get(); |
| 1352 | if (a->hidden()) |
| 1353 | continue; |
| 1354 | |
| 1355 | std::string nameDescrip = a->nameDescrip(); |
| 1356 | |
| 1357 | info.push_back(std::make_pair(nameDescrip, a->description())); |
| 1358 | namelen = (std::max)(namelen, nameDescrip.size()); |
| 1359 | } |
| 1360 | size_t secondIndent = indent + 4; |
| 1361 | int postNameSpacing = 2; |
| 1362 | size_t leadlen = namelen + indent + postNameSpacing; |
| 1363 | size_t firstlen = totalWidth - leadlen - 1; |
| 1364 | size_t secondLen = totalWidth - secondIndent - 1; |
| 1365 | |
| 1366 | bool skipfirst = (firstlen < 10); |
| 1367 | if (skipfirst) |
| 1368 | firstlen = secondLen; |
| 1369 | |
| 1370 | for (auto i : info) |
| 1371 | { |
| 1372 | std::vector<std::string> descrip = |
| 1373 | Utils::wordWrap(i.second, secondLen, firstlen); |
| 1374 | |
| 1375 | std::string name = i.first; |
| 1376 | out << std::string(indent, ' '); |
| 1377 | if (skipfirst) |
| 1378 | out << name << std::endl; |
| 1379 | else |
| 1380 | { |
| 1381 | name.resize(namelen, ' '); |
| 1382 | out << name << std::string(postNameSpacing, ' ') << |
| 1383 | descrip[0] << std::endl; |
| 1384 | } |
| 1385 | for (size_t ii = 1; ii < descrip.size(); ++ii) |
| 1386 | out << std::string(secondIndent, ' ') << |
| 1387 | descrip[ii] << std::endl; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | Write a verbose description of arguments to an output stream. Each |
no test coverage detected