format help description
This commit is contained in:
parent
96b2e09b69
commit
2e4c78805d
@ -79,7 +79,50 @@ namespace cxxopts
|
|||||||
int width
|
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();
|
auto fiter = format.begin();
|
||||||
for (const auto& o : group->second)
|
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;
|
result += fiter->first;
|
||||||
if (fiter->first.size() > longest)
|
if (fiter->first.size() > longest)
|
||||||
|
@ -37,7 +37,9 @@ int main(int argc, char* argv[])
|
|||||||
("a,apple", "an apple")
|
("a,apple", "an apple")
|
||||||
("b,bob", "Bob")
|
("b,bob", "Bob")
|
||||||
("f,file", "File", cxxopts::value<std::vector<std::string>>())
|
("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")
|
("help", "Print help")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user