[PATCH] D57030: [CommandLine] Don't print empty sentinel values from EnumValN lists in help text
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 23 07:14:37 PST 2019
jhenderson updated this revision to Diff 183097.
jhenderson edited the summary of this revision.
jhenderson added a reviewer: chandlerc.
jhenderson added a comment.
I've tweaked the output as discussed. For a ValueOptional with sentinel value, it prints something like the following:
-mhvx - Enable Hexagon Vector eXtensions
-mhvx=<value> - Enable Hexagon Vector eXtensions
=v60 - Build for HVX v60
=v62 - Build for HVX v62
=v65 - Build for HVX v65
=v66 - Build for HVX v66
Without a sentinel value it prints:
-mhvx=<value> - Enable Hexagon Vector eXtensions
=v60 - Build for HVX v60
=v62 - Build for HVX v62
=v65 - Build for HVX v65
=v66 - Build for HVX v66
For ValueRequired with an empty string value it prints:
-mhvx=<value> - Enable Hexagon Vector eXtensions
=v60 - Build for HVX v60
=v62 - Build for HVX v62
=v65 - Build for HVX v65
=v66 - Build for HVX v66
=<empty>
The latter also demonstrates what happens if the description is empty.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57030/new/
https://reviews.llvm.org/D57030
Files:
lib/Support/CommandLine.cpp
Index: lib/Support/CommandLine.cpp
===================================================================
--- lib/Support/CommandLine.cpp
+++ lib/Support/CommandLine.cpp
@@ -1672,13 +1672,35 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57030.183097.patch
Type: text/x-patch
Size: 1824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190123/4f98e4ee/attachment.bin>
More information about the llvm-commits
mailing list