diff options
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index f8bc6a8f615..886595e30a5 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1663,13 +1663,35 @@ size_t generic_parser_base::getOptionWidth(const Option &O) const { void generic_parser_base::printOptionInfo(const Option &O, size_t GlobalWidth) const { if (O.hasArgStr()) { - outs() << " -" << O.ArgStr; - Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 6); + // When the value is optional, first print a line just describing the option + // without values. + if (O.getValueExpectedFlag() == ValueOptional) { + for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { + if (getOption(i).empty()) { + outs() << " -" << O.ArgStr; + Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 6); + break; + } + } + } + outs() << " -" << O.ArgStr << "=<value>"; + Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 14); for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { - size_t NumSpaces = GlobalWidth - getOption(i).size() - 8; - outs() << " =" << getOption(i); - outs().indent(NumSpaces) << " - " << getDescription(i) << '\n'; + StringRef ValueName = getOption(i); + StringRef Description = getDescription(i); + if (O.getValueExpectedFlag() == ValueOptional && ValueName.empty() && + Description.empty()) + continue; + size_t NumSpaces = GlobalWidth - ValueName.size() - 8; + outs() << " =" << ValueName; + if (ValueName.empty()) { + outs() << "<empty>"; + NumSpaces -= 7; + } + if (!Description.empty()) + outs().indent(NumSpaces) << " - " << Description; + outs() << '\n'; } } else { if (!O.HelpStr.empty()) |