1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[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

llvm-svn: 344097
This commit is contained in:
Fangrui Song 2018-10-10 00:15:31 +00:00
parent aa4a00c53a
commit e7dda9d340
11 changed files with 26 additions and 22 deletions

View File

@ -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;
};

View File

@ -521,19 +521,17 @@ static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
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.

View File

@ -96,7 +96,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
// 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;
}

View File

@ -123,7 +123,7 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
// 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;
}

View File

@ -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:

View File

@ -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.

View File

@ -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;
}

View File

@ -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;
}

View File

@ -897,12 +897,12 @@ static DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
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(ArrayRef<const char *> ArgsArr) {
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);
}

View File

@ -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;
}

View File

@ -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());