format help description

This commit is contained in:
Jarryd Beck 2014-10-13 14:30:56 +11:00
parent 96b2e09b69
commit 2e4c78805d
2 changed files with 48 additions and 3 deletions

View File

@ -79,7 +79,50 @@ namespace cxxopts
int width
)
{
return text;
std::string result;
auto current = text.begin();
auto startLine = current;
auto lastSpace = current;
int size = 0;
while (current != text.end())
{
if (*current == ' ')
{
lastSpace = current;
}
if (size > width)
{
if (lastSpace == startLine)
{
result.append(startLine, current + 1);
result.append("\n");
result.append(start, ' ');
}
else
{
result.append(startLine, current);
result.append("\n");
result.append(start, ' ');
}
startLine = lastSpace + 1;
size = 0;
}
else
{
++size;
}
++current;
}
//append whatever is left
result.append(startLine, current);
return result;
}
}
@ -367,7 +410,7 @@ Options::help() const
auto fiter = format.begin();
for (const auto& o : group->second)
{
auto d = format_description(o.desc, longest, allowed);
auto d = format_description(o.desc, longest + OPTION_DESC_GAP, allowed);
result += fiter->first;
if (fiter->first.size() > longest)

View File

@ -37,7 +37,9 @@ int main(int argc, char* argv[])
("a,apple", "an apple")
("b,bob", "Bob")
("f,file", "File", cxxopts::value<std::vector<std::string>>())
("positional", "Positional arguments", cxxopts::value<std::string>())
("positional",
"Positional arguments: these are the arguments that are entered "
"without an option", cxxopts::value<std::string>())
("help", "Print help")
;