/// This function just prints the help message, exactly the same way as if the
/// -help or -help-hidden option had been given on the command line.
///
-/// NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
-///
/// \param Hidden if true will print hidden options
/// \param Categorized if true print options in categories
void PrintHelpMessage(bool Hidden = false, bool Categorized = false);
void operator=(bool Value) {
if (!Value)
return;
+ printHelp();
+ // Halt the program since help information was printed
+ exit(0);
+ }
+
+ void printHelp() {
SubCommand *Sub = GlobalParser->getActiveSubCommand();
auto &OptionsMap = Sub->OptionsMap;
auto &PositionalOpts = Sub->PositionalOpts;
for (auto I : GlobalParser->MoreHelp)
outs() << I;
GlobalParser->MoreHelp.clear();
-
- // Halt the program since help information was printed
- exit(0);
}
};
// Utility function for printing the help message.
void cl::PrintHelpMessage(bool Hidden, bool Categorized) {
- // This looks weird, but it actually prints the help message. The Printers are
- // types of HelpPrinter and the help gets printed when its operator= is
- // invoked. That's because the "normal" usages of the help printer is to be
- // assigned true/false depending on whether -help or -help-hidden was given or
- // not. Since we're circumventing that we have to make it look like -help or
- // -help-hidden were given, so we assign true.
-
if (!Hidden && !Categorized)
- UncategorizedNormalPrinter = true;
+ UncategorizedNormalPrinter.printHelp();
else if (!Hidden && Categorized)
- CategorizedNormalPrinter = true;
+ CategorizedNormalPrinter.printHelp();
else if (Hidden && !Categorized)
- UncategorizedHiddenPrinter = true;
+ UncategorizedHiddenPrinter.printHelp();
else
- CategorizedHiddenPrinter = true;
+ CategorizedHiddenPrinter.printHelp();
}
/// Utility function for printing version number.
// Show the error message and exit.
LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
errs() << ToolName << ": " << Error << ".\n";
- // FIXME: Other ar implementations will print the command line help in here.
- // Unfortunately cl::PrintHelpMessage() exits with 0, so we can't call it.
+ cl::PrintHelpMessage();
exit(1);
}