[llvm] r344097 - [opt] Change the parameter of OptTable::PrintHelp from Name to Usage and don't append "[options] <inputs>"
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 9 17:15:31 PDT 2018
Author: maskray
Date: Tue Oct 9 17:15:31 2018
New Revision: 344097
URL: http://llvm.org/viewvc/llvm-project?rev=344097&view=rev
Log:
[opt] Change the parameter of OptTable::PrintHelp from Name to Usage and don't append "[options] <inputs>"
Summary:
Before, "[options] <inputs>" is unconditionally appended to the `Name` parameter. It is more flexible to change its semantic to `Usage` and let user customize the usage line.
% llvm-objcopy
...
USAGE: llvm-objcopy <input> [ <output> ] [options] <inputs>
With this patch:
% llvm-objcopy
...
USAGE: llvm-objcopy input [output]
Reviewers: rupprecht, alexshap, jhenderson
Reviewed By: rupprecht
Subscribers: jakehehrlich, mehdi_amini, steven_wu, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D51009
Modified:
llvm/trunk/include/llvm/Option/OptTable.h
llvm/trunk/lib/Option/OptTable.cpp
llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
llvm/trunk/test/tools/llvm-cvtres/help.test
llvm/trunk/test/tools/llvm-rc/helpmsg.test
llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
llvm/trunk/tools/llvm-mt/llvm-mt.cpp
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
llvm/trunk/tools/llvm-rc/llvm-rc.cpp
llvm/trunk/unittests/Option/OptionParsingTest.cpp
Modified: llvm/trunk/include/llvm/Option/OptTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/OptTable.h?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Option/OptTable.h (original)
+++ llvm/trunk/include/llvm/Option/OptTable.h Tue Oct 9 17:15:31 2018
@@ -217,8 +217,8 @@ public:
/// 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 Title - The title to use in the usage line.
+ /// \param Usage - USAGE: Usage
+ /// \param Title - OVERVIEW: Title
/// \param FlagsToInclude - If non-zero, only include options with any
/// of these flags set.
/// \param FlagsToExclude - Exclude options with any of these flags set.
@@ -226,11 +226,11 @@ public:
/// 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 *Usage, 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 *Usage, const char *Title,
bool ShowHidden = false, bool ShowAllAliases = false) const;
};
Modified: llvm/trunk/lib/Option/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/OptTable.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/lib/Option/OptTable.cpp (original)
+++ llvm/trunk/lib/Option/OptTable.cpp Tue Oct 9 17:15:31 2018
@@ -521,19 +521,17 @@ static const char *getOptionHelpGroup(co
return getOptionHelpGroup(Opts, GroupID);
}
-void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
+void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
bool ShowHidden, bool ShowAllAliases) const {
- PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
+ PrintHelp(OS, Usage, 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 *Usage, 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 << "OVERVIEW: " << Title << "\n\n";
+ OS << "USAGE: " << Usage << "\n\n";
// Render help text into a map of group-name to a list of (option, help)
// pairs.
Modified: llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp (original)
+++ llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp Tue Oct 9 17:15:31 2018
@@ -96,7 +96,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayR
// Handle when no input or output is specified
if (Args.hasArgNoClaim(OPT_INPUT) ||
(!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
- Table.PrintHelp(outs(), ArgsArr[0], "dlltool", false);
+ Table.PrintHelp(outs(), "llvm-dlltool [options] file...", "llvm-dlltool",
+ false);
llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64\n";
return 1;
}
Modified: llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp (original)
+++ llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp Tue Oct 9 17:15:31 2018
@@ -123,7 +123,7 @@ int llvm::libDriverMain(ArrayRef<const c
// Handle /help
if (Args.hasArg(OPT_help)) {
- Table.PrintHelp(outs(), ArgsArr[0], "LLVM Lib");
+ Table.PrintHelp(outs(), "llvm-lib [options] file...", "LLVM Lib");
return 0;
}
Modified: llvm/trunk/test/tools/llvm-cvtres/help.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cvtres/help.test?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cvtres/help.test (original)
+++ llvm/trunk/test/tools/llvm-cvtres/help.test Tue Oct 9 17:15:31 2018
@@ -2,7 +2,7 @@
; RUN: FileCheck -input-file=%t %s -check-prefix=HELP_TEST
; HELP_TEST: OVERVIEW: Resource Converter
-; HELP_TEST-DAG: USAGE: cvtres [options] <inputs>
+; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file...
; HELP_TEST-DAG: OPTIONS:
; HELP_TEST-NEXT: /DEFINE:symbol
; HELP_TEST-NEXT: /FOLDDUPS:
Modified: llvm/trunk/test/tools/llvm-rc/helpmsg.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-rc/helpmsg.test?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-rc/helpmsg.test (original)
+++ llvm/trunk/test/tools/llvm-rc/helpmsg.test Tue Oct 9 17:15:31 2018
@@ -4,7 +4,7 @@
; RUN: FileCheck -input-file=%t1 %s
; CHECK: OVERVIEW: Resource Converter
-; CHECK-DAG: USAGE: rc [options] <inputs>
+; CHECK-DAG: USAGE: rc [options] file...
; CHECK-DAG: OPTIONS:
; CHECK-NEXT: /? Display this help and exit.
; CHECK-NEXT: /C <value> Set the codepage used for input strings.
Modified: llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp (original)
+++ llvm/trunk/tools/llvm-cvtres/llvm-cvtres.cpp Tue Oct 9 17:15:31 2018
@@ -103,7 +103,7 @@ int main(int Argc, const char **Argv) {
opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
if (InputArgs.hasArg(OPT_HELP)) {
- T.PrintHelp(outs(), "cvtres", "Resource Converter", false);
+ T.PrintHelp(outs(), "llvm-cvtres [options] file...", "Resource Converter", false);
return 0;
}
Modified: llvm/trunk/tools/llvm-mt/llvm-mt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mt/llvm-mt.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mt/llvm-mt.cpp (original)
+++ llvm/trunk/tools/llvm-mt/llvm-mt.cpp Tue Oct 9 17:15:31 2018
@@ -115,7 +115,7 @@ int main(int Argc, const char **Argv) {
}
if (InputArgs.hasArg(OPT_help)) {
- T.PrintHelp(outs(), "mt", "Manifest Tool", false);
+ T.PrintHelp(outs(), "llvm-mt [options] file...", "Manifest Tool", false);
return 0;
}
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Tue Oct 9 17:15:31 2018
@@ -897,12 +897,12 @@ static DriverConfig parseObjcopyOptions(
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
if (InputArgs.size() == 0) {
- T.PrintHelp(errs(), "llvm-objcopy <input> [ <output> ]", "objcopy tool");
+ T.PrintHelp(errs(), "llvm-objcopy input [output]", "objcopy tool");
exit(1);
}
if (InputArgs.hasArg(OBJCOPY_help)) {
- T.PrintHelp(outs(), "llvm-objcopy <input> [ <output> ]", "objcopy tool");
+ T.PrintHelp(outs(), "llvm-objcopy input [output]", "objcopy tool");
exit(0);
}
@@ -1039,13 +1039,14 @@ static DriverConfig parseStripOptions(Ar
llvm::opt::InputArgList InputArgs =
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
+ static const char Usage[] = "llvm-strip [options] file...";
if (InputArgs.size() == 0) {
- T.PrintHelp(errs(), "llvm-strip", "strip tool");
+ T.PrintHelp(errs(), Usage, "strip tool");
exit(1);
}
if (InputArgs.hasArg(STRIP_help)) {
- T.PrintHelp(outs(), "llvm-strip", "strip tool");
+ T.PrintHelp(outs(), Usage, "strip tool");
exit(0);
}
Modified: llvm/trunk/tools/llvm-rc/llvm-rc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rc/llvm-rc.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rc/llvm-rc.cpp (original)
+++ llvm/trunk/tools/llvm-rc/llvm-rc.cpp Tue Oct 9 17:15:31 2018
@@ -90,7 +90,7 @@ int main(int Argc, const char **Argv) {
// The tool prints nothing when invoked with no command-line arguments.
if (InputArgs.hasArg(OPT_HELP)) {
- T.PrintHelp(outs(), "rc", "Resource Converter", false);
+ T.PrintHelp(outs(), "rc [options] file...", "Resource Converter", false);
return 0;
}
Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=344097&r1=344096&r2=344097&view=diff
==============================================================================
--- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)
+++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Tue Oct 9 17:15:31 2018
@@ -97,6 +97,10 @@ TEST(Option, OptionParsing) {
T.PrintHelp(RSO, "test", "title!");
EXPECT_NE(std::string::npos, Help.find("-A"));
+ // Check usage line.
+ T.PrintHelp(RSO, "name [options] file...", "title!");
+ EXPECT_NE(std::string::npos, Help.find("USAGE: name [options] file...\n"));
+
// Test aliases.
auto Cs = AL.filtered(OPT_C);
ASSERT_NE(Cs.begin(), Cs.end());
More information about the llvm-commits
mailing list