[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
Thu Jan 24 06:09:55 PST 2019


jhenderson updated this revision to Diff 183296.
jhenderson added a comment.
Herald added a subscriber: rupprecht.

Remove colon from help text, which now won't have anything listed after it. Without this change, the following would have been the output of llvm-symbolizer --help with this patch:

  -functions                        - Print function name for a given address:
  -functions=<value>                - Print function name for a given address:
    =none                           -   omit function name
    =short                          -   print short function name
    =linkage                        -   print function linkage name (default)

I checked and couldn't find anywhere else that would be impacted in this way.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57030/new/

https://reviews.llvm.org/D57030

Files:
  lib/Support/CommandLine.cpp
  tools/llvm-symbolizer/llvm-symbolizer.cpp


Index: tools/llvm-symbolizer/llvm-symbolizer.cpp
===================================================================
--- tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -38,7 +38,7 @@
 
 static cl::opt<FunctionNameKind> ClPrintFunctions(
     "functions", cl::init(FunctionNameKind::LinkageName),
-    cl::desc("Print function name for a given address:"), cl::ValueOptional,
+    cl::desc("Print function name for a given address"), cl::ValueOptional,
     cl::values(clEnumValN(FunctionNameKind::None, "none", "omit function name"),
                clEnumValN(FunctionNameKind::ShortName, "short",
                           "print short function name"),
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.183296.patch
Type: text/x-patch
Size: 2523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190124/01a3bc54/attachment.bin>


More information about the llvm-commits mailing list