]> granicus.if.org Git - llvm/commitdiff
[libOption] - Add flag allowing to print options aliases in help text.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 26 Jul 2017 09:09:56 +0000 (09:09 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 26 Jul 2017 09:09:56 +0000 (09:09 +0000)
By default, we display only options that are not
hidden and have help texts. This patch adds flag
allowing to display aliases that have no help text.
In this case help text of aliased option used instead.

Differential revision: https://reviews.llvm.org/D35476

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309087 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a35e182f00e53ba57bfa06fd7a9ea6e41882c53d..6acece967038c31f27bfffcce7a3043fa6c967b4 100644 (file)
@@ -191,12 +191,16 @@ public:
   /// \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, bool ShowHidden = false) const;
+  /// \param ShowAllAliases - If true, display all options including aliases
+  ///                         that don't have help texts. By default, we display
+  ///                         only options that are not hidden and have help
+  ///                         texts.
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 unsigned FlagsToInclude, unsigned FlagsToExclude,
+                 bool ShowAllAliases) const;
+
+  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+                 bool ShowHidden = false, bool ShowAllAliases = false) const;
 };
 
 } // end namespace opt
index f3b438e829d66c3b7a5eccfc0ac9bf99ceb2b06b..071c9db87206e283dd1ff7be3d5022b86dbd1db0 100644 (file)
@@ -444,15 +444,14 @@ static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
 }
 
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         bool ShowHidden) const {
+                         bool ShowHidden, bool ShowAllAliases) const {
   PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
-            (ShowHidden ? 0 : HelpHidden));
+            (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
 }
 
-
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
-                         unsigned FlagsToInclude,
-                         unsigned FlagsToExclude) const {
+                         unsigned FlagsToInclude, unsigned FlagsToExclude,
+                         bool ShowAllAliases) const {
   OS << "OVERVIEW: " << Title << "\n";
   OS << '\n';
   OS << "USAGE: " << Name << " [options] <inputs>\n";
@@ -476,10 +475,19 @@ void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
     if (Flags & FlagsToExclude)
       continue;
 
-    if (const char *Text = getOptionHelpText(Id)) {
+    // If an alias doesn't have a help text, show a help text for the aliased
+    // option instead.
+    const char *HelpText = getOptionHelpText(Id);
+    if (!HelpText && ShowAllAliases) {
+      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});
     }
   }