[PATCH] D51009: [opt] Make OptTable::PrintHelp append "[options] <inputs>" conditionally

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 20 16:18:29 PDT 2018


MaskRay created this revision.
MaskRay added a reviewer: rupprecht.
Herald added a reviewer: alexshap.
Herald added a subscriber: llvm-commits.

Before, "[options] <inputs>" is unconditionally appended:

% llvm-objcopy
...
USAGE: llvm-objcopy <input> [ <output> ] [options] <inputs>

With this patch:

% llvm-objcopy
...
USAGE: llvm-objcopy <input> [ <output> ]


Repository:
  rL LLVM

https://reviews.llvm.org/D51009

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


Index: lib/Option/OptTable.cpp
===================================================================
--- lib/Option/OptTable.cpp
+++ lib/Option/OptTable.cpp
@@ -521,18 +521,20 @@
   return getOptionHelpGroup(Opts, GroupID);
 }
 
-void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+void OptTable::PrintHelp(raw_ostream &OS, const char *NameOrUsage, const char *Title,
                          bool ShowHidden, bool ShowAllAliases) const {
-  PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
+  PrintHelp(OS, NameOrUsage, Title, /*Include*/ 0, /*Exclude*/
             (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
 }
 
-void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+void OptTable::PrintHelp(raw_ostream &OS, const char *NameOrUsage, const char *Title,
                          unsigned FlagsToInclude, unsigned FlagsToExclude,
                          bool ShowAllAliases) const {
   OS << "OVERVIEW: " << Title << "\n";
   OS << '\n';
-  OS << "USAGE: " << Name << " [options] <inputs>\n";
+  OS << "USAGE: " << NameOrUsage;
+  if (!strchr(NameOrUsage, ' '))
+    OS << " [options] <inputs>\n";
   OS << '\n';
 
   // Render help text into a map of group-name to a list of (option, help)
Index: include/llvm/Option/OptTable.h
===================================================================
--- include/llvm/Option/OptTable.h
+++ include/llvm/Option/OptTable.h
@@ -217,20 +217,21 @@
   /// Render the help text for an option table.
   ///
   /// \param OS - The stream to write the help text to.
-  /// \param Name - The name to use in the usage line.
+  /// \param NameOrUsage - The usage line. If without space, "[options] <inputs>"
+  ///                      will be appended.
   /// \param Title - The title to use in the usage line.
   /// \param FlagsToInclude - If non-zero, only include options with any
   ///                         of these flags set.
   /// \param FlagsToExclude - Exclude options with any of these flags set.
   /// \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,
+  void PrintHelp(raw_ostream &OS, const char *NameOrUsage, const char *Title,
                  unsigned FlagsToInclude, unsigned FlagsToExclude,
                  bool ShowAllAliases) const;
 
-  void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+  void PrintHelp(raw_ostream &OS, const char *NameOrUsage, const char *Title,
                  bool ShowHidden = false, bool ShowAllAliases = false) const;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51009.161610.patch
Type: text/x-patch
Size: 2793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180820/3d6d1e14/attachment.bin>


More information about the llvm-commits mailing list