diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2019-01-31 13:58:48 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2019-01-31 13:58:48 +0000 |
commit | 140f75f625bc815c5c7c73a6ba765d49998f95c4 (patch) | |
tree | 2ae738c8cc2a0c5c6a2d70cd9aa7dbdb7ef440ff /llvm/lib/Support/CommandLine.cpp | |
parent | ac1b75b5c5b77f641ca1e0ecbc9dc3c89a6303c3 (diff) | |
download | bcm5719-llvm-140f75f625bc815c5c7c73a6ba765d49998f95c4.tar.gz bcm5719-llvm-140f75f625bc815c5c7c73a6ba765d49998f95c4.zip |
[CommandLine] Improve help text for cl::values style options
In order to make an option value truly optional, both the ValueOptional
and an empty-named value are required. This empty-named value appears in
the command-line help text, which is not ideal.
This change improves the help text for these sort of options in a number
of ways:
1) ValueOptional options with an empty-named value now print their help
text twice: both without and then with '=<value>' after the name. The
latter version then lists the allowed values after it.
2) Empty-named values with no help text in ValueOptional options are not
listed in the permitted values.
3) Otherwise empty-named options are printed as =<empty> rather than
simply '='.
4) Option values without help text do not have the '-' separator
printed.
It also tweaks the llvm-symbolizer -functions help text to not print a
trailing ':' as that looks bad combined with 1) above.
Reviewed by: thopre, ruiu
Differential Revision: https://reviews.llvm.org/D57030
llvm-svn: 352750
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()) |