llvm.org GIT mirror llvm / 42f63b6
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344097 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 10 months ago
11 changed file(s) with 26 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
216216 /// Render the help text for an option table.
217217 ///
218218 /// \param OS - The stream to write the help text to.
219 /// \param Name - The name to use in the usage line.
220 /// \param Title - The title to use in the usage line.
219 /// \param Usage - USAGE: Usage
220 /// \param Title - OVERVIEW: Title
221221 /// \param FlagsToInclude - If non-zero, only include options with any
222222 /// of these flags set.
223223 /// \param FlagsToExclude - Exclude options with any of these flags set.
225225 /// that don't have help texts. By default, we display
226226 /// only options that are not hidden and have help
227227 /// texts.
228 void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
228 void PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
229229 unsigned FlagsToInclude, unsigned FlagsToExclude,
230230 bool ShowAllAliases) const;
231231
232 void PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
232 void PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
233233 bool ShowHidden = false, bool ShowAllAliases = false) const;
234234 };
235235
520520 return getOptionHelpGroup(Opts, GroupID);
521521 }
522522
523 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
523 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
524524 bool ShowHidden, bool ShowAllAliases) const {
525 PrintHelp(OS, Name, Title, /*Include*/ 0, /*Exclude*/
525 PrintHelp(OS, Usage, Title, /*Include*/ 0, /*Exclude*/
526526 (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
527527 }
528528
529 void OptTable::PrintHelp(raw_ostream &OS, const char *Name, const char *Title,
529 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
530530 unsigned FlagsToInclude, unsigned FlagsToExclude,
531531 bool ShowAllAliases) const {
532 OS << "OVERVIEW: " << Title << "\n";
533 OS << '\n';
534 OS << "USAGE: " << Name << " [options] \n";
535 OS << '\n';
532 OS << "OVERVIEW: " << Title << "\n\n";
533 OS << "USAGE: " << Usage << "\n\n";
536534
537535 // Render help text into a map of group-name to a list of (option, help)
538536 // pairs.
9595 // Handle when no input or output is specified
9696 if (Args.hasArgNoClaim(OPT_INPUT) ||
9797 (!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
98 Table.PrintHelp(outs(), ArgsArr[0], "dlltool", false);
98 Table.PrintHelp(outs(), "llvm-dlltool [options] file...", "llvm-dlltool",
99 false);
99100 llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64\n";
100101 return 1;
101102 }
122122
123123 // Handle /help
124124 if (Args.hasArg(OPT_help)) {
125 Table.PrintHelp(outs(), ArgsArr[0], "LLVM Lib");
125 Table.PrintHelp(outs(), "llvm-lib [options] file...", "LLVM Lib");
126126 return 0;
127127 }
128128
11 ; RUN: FileCheck -input-file=%t %s -check-prefix=HELP_TEST
22
33 ; HELP_TEST: OVERVIEW: Resource Converter
4 ; HELP_TEST-DAG: USAGE: cvtres [options]
4 ; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file...
55 ; HELP_TEST-DAG: OPTIONS:
66 ; HELP_TEST-NEXT: /DEFINE:symbol
77 ; HELP_TEST-NEXT: /FOLDDUPS:
33 ; RUN: FileCheck -input-file=%t1 %s
44
55 ; CHECK: OVERVIEW: Resource Converter
6 ; CHECK-DAG: USAGE: rc [options]
6 ; CHECK-DAG: USAGE: rc [options] file...
77 ; CHECK-DAG: OPTIONS:
88 ; CHECK-NEXT: /? Display this help and exit.
99 ; CHECK-NEXT: /C Set the codepage used for input strings.
102102 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
103103
104104 if (InputArgs.hasArg(OPT_HELP)) {
105 T.PrintHelp(outs(), "cvtres", "Resource Converter", false);
105 T.PrintHelp(outs(), "llvm-cvtres [options] file...", "Resource Converter", false);
106106 return 0;
107107 }
108108
114114 }
115115
116116 if (InputArgs.hasArg(OPT_help)) {
117 T.PrintHelp(outs(), "mt", "Manifest Tool", false);
117 T.PrintHelp(outs(), "llvm-mt [options] file...", "Manifest Tool", false);
118118 return 0;
119119 }
120120
896896 T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
897897
898898 if (InputArgs.size() == 0) {
899 T.PrintHelp(errs(), "llvm-objcopy [ ]", "objcopy tool");
899 T.PrintHelp(errs(), "llvm-objcopy input [output]", "objcopy tool");
900900 exit(1);
901901 }
902902
903903 if (InputArgs.hasArg(OBJCOPY_help)) {
904 T.PrintHelp(outs(), "llvm-objcopy [ ]", "objcopy tool");
904 T.PrintHelp(outs(), "llvm-objcopy input [output]", "objcopy tool");
905905 exit(0);
906906 }
907907
10381038 llvm::opt::InputArgList InputArgs =
10391039 T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
10401040
1041 static const char Usage[] = "llvm-strip [options] file...";
10411042 if (InputArgs.size() == 0) {
1042 T.PrintHelp(errs(), "llvm-strip", "strip tool");
1043 T.PrintHelp(errs(), Usage, "strip tool");
10431044 exit(1);
10441045 }
10451046
10461047 if (InputArgs.hasArg(STRIP_help)) {
1047 T.PrintHelp(outs(), "llvm-strip", "strip tool");
1048 T.PrintHelp(outs(), Usage, "strip tool");
10481049 exit(0);
10491050 }
10501051
8989
9090 // The tool prints nothing when invoked with no command-line arguments.
9191 if (InputArgs.hasArg(OPT_HELP)) {
92 T.PrintHelp(outs(), "rc", "Resource Converter", false);
92 T.PrintHelp(outs(), "rc [options] file...", "Resource Converter", false);
9393 return 0;
9494 }
9595
9696 T.PrintHelp(RSO, "test", "title!");
9797 EXPECT_NE(std::string::npos, Help.find("-A"));
9898
99 // Check usage line.
100 T.PrintHelp(RSO, "name [options] file...", "title!");
101 EXPECT_NE(std::string::npos, Help.find("USAGE: name [options] file...\n"));
102
99103 // Test aliases.
100104 auto Cs = AL.filtered(OPT_C);
101105 ASSERT_NE(Cs.begin(), Cs.end());