[PATCH] D35476: [libOption] - Add flag allowing to print options aliases in help text.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 02:48:43 PDT 2017


grimar updated this revision to Diff 107870.
grimar edited the summary of this revision.
grimar added a comment.

- Reimplemented.

`ShowAliases` flag allows to specify that alias should take HelpText from its
parent option. In that case we can have for example:

  def auxiliary: S<"auxiliary">, HelpText<"Set DT_AUXILIARY field to the specified name">;
  def alias_auxiliary: Separate<["-"], "f">, Alias<auxiliary>;

and show both options in help:

  --auxiliary <value> Set DT_AUXILIARY field to the specified name
  -f <value>              Set DT_AUXILIARY field to the specified name

Without that change we would render only first line in --help.


https://reviews.llvm.org/D35476

Files:
  include/llvm/Option/OptTable.h
  lib/Option/OptTable.cpp


Index: lib/Option/OptTable.cpp
===================================================================
--- lib/Option/OptTable.cpp
+++ lib/Option/OptTable.cpp
@@ -444,15 +444,14 @@
 }
 
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         bool ShowHidden) const {
+                         bool ShowHidden, bool ShowAliases) const {
   PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
-            (ShowHidden ? 0 : HelpHidden));
+            (ShowHidden ? 0 : HelpHidden), ShowAliases);
 }
 
-
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         unsigned FlagsToInclude,
-                         unsigned FlagsToExclude) const {
+                         unsigned FlagsToInclude, unsigned FlagsToExclude,
+                         bool ShowAliases) const {
   OS << "OVERVIEW: " << Title << "\n";
   OS << '\n';
   OS << "USAGE: " << Name << " [options] <inputs>\n";
@@ -476,10 +475,21 @@
     if (Flags & FlagsToExclude)
       continue;
 
-    if (const char *Text = getOptionHelpText(Id)) {
+    // Aliases usually do not have help text set explicitly. If we want to show
+    // such aliases in help, we use associated aliased option help text value.
+    // If both alias and aliased option has no text, that proably means option
+    // is ignored.
+    const char *HelpText = getOptionHelpText(Id);
+    if (!HelpText && ShowAliases) {
+      const Option Alias = getOption(Id).getAlias();
+      if (Alias.isValid())
+        HelpText = getOptionHelpText(Alias.getID());
+    }
+
+    if (HelpText) {
       const char *HelpGroup = getOptionHelpGroup(*this, Id);
       const std::string &OptName = getOptionHelpName(*this, Id);
-      GroupedOptionHelp[HelpGroup].push_back({OptName, Text});
+      GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
     }
   }
 
Index: include/llvm/Option/OptTable.h
===================================================================
--- include/llvm/Option/OptTable.h
+++ include/llvm/Option/OptTable.h
@@ -191,12 +191,12 @@
   /// \param FlagsToInclude - If non-zero, only include options with any
   ///                         of these flags set.
   /// \param FlagsToExclude - Exclude options with any of these flags set.
-  void PrintHelp(raw_ostream &OS, const char *Name,
-                 const char *Title, unsigned FlagsToInclude,
-                 unsigned FlagsToExclude) const;
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 unsigned FlagsToInclude, unsigned FlagsToExclude,
+                 bool ShowAliases) const;
 
-  void PrintHelp(raw_ostream &OS, const char *Name,
-                  const char *Title, bool ShowHidden = false) const;
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 bool ShowHidden = false, bool ShowAliases = false) const;
 };
 
 } // end namespace opt


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35476.107870.patch
Type: text/x-patch
Size: 2943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170724/f65cf9c2/attachment.bin>


More information about the llvm-commits mailing list