[PATCH] D51009: [opt] Make OptTable::PrintHelp append "[options] <inputs>" conditionally
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 22 10:29:57 PDT 2018
MaskRay updated this revision to Diff 161993.
MaskRay added a comment.
Add test to unittests/Option/OptionParsingTest.cpp
Repository:
rL LLVM
https://reviews.llvm.org/D51009
Files:
include/llvm/Option/OptTable.h
lib/Option/OptTable.cpp
unittests/Option/OptionParsingTest.cpp
Index: unittests/Option/OptionParsingTest.cpp
===================================================================
--- unittests/Option/OptionParsingTest.cpp
+++ unittests/Option/OptionParsingTest.cpp
@@ -97,6 +97,12 @@
T.PrintHelp(RSO, "test", "title!");
EXPECT_NE(std::string::npos, Help.find("-A"));
+ // Check usage line.
+ T.PrintHelp(RSO, "name", "title!");
+ EXPECT_NE(std::string::npos, Help.find("USAGE: name [options] <inputs>\n"));
+ T.PrintHelp(RSO, "name <input>", "title!");
+ EXPECT_NE(std::string::npos, Help.find("USAGE: name <input>\n"));
+
// Test aliases.
auto Cs = AL.filtered(OPT_C);
ASSERT_NE(Cs.begin(), Cs.end());
Index: lib/Option/OptTable.cpp
===================================================================
--- lib/Option/OptTable.cpp
+++ lib/Option/OptTable.cpp
@@ -521,19 +521,21 @@
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 << '\n';
+ OS << "USAGE: " << NameOrUsage;
+ if (!strchr(NameOrUsage, ' '))
+ OS << " [options] <inputs>";
+ OS << "\n\n";
// Render help text into a map of group-name to a list of (option, help)
// pairs.
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.161993.patch
Type: text/x-patch
Size: 3481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/efa6269e/attachment.bin>
More information about the llvm-commits
mailing list