#include "llvm/Config/config.h"
#include "llvm/Support/CommandLine.h"
#include <algorithm>
+#include <functional>
#include <map>
#include <set>
#include <iostream>
// Check out the positional arguments to collect information about them.
unsigned NumPositionalRequired = 0;
+
+ // Determine whether or not there are an unlimited number of positionals
+ bool HasUnlimitedPositionals = false;
+
Option *ConsumeAfterOpt = 0;
if (!PositionalOpts.empty()) {
if (PositionalOpts[0]->getNumOccurrencesFlag() == cl::ConsumeAfter) {
}
UnboundedFound |= EatsUnboundedNumberOfValues(Opt);
}
+ HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
}
// PositionalVals - A vector of "positional" arguments we accumulate into
}
if (Handler == 0) {
- std::cerr << ProgramName << ": Unknown command line argument '" << argv[i]
- << "'. Try: '" << argv[0] << " --help'\n";
+ if (ProgramName)
+ std::cerr << ProgramName << ": Unknown command line argument '"
+ << argv[i] << "'. Try: '" << argv[0] << " --help'\n";
+ else
+ std::cerr << "Unknown command line argument '" << argv[i] << "'.\n";
ErrorParsing = true;
continue;
}
// Check and handle positional arguments now...
if (NumPositionalRequired > PositionalVals.size()) {
- std::cerr << ProgramName
- << ": Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments: See: " << argv[0] << " --help\n";
+ if (ProgramName)
+ std::cerr << ProgramName
+ << ": Not enough positional command line arguments specified!\n"
+ << "Must specify at least " << NumPositionalRequired
+ << " positional arguments: See: " << argv[0] << " --help\n";
+ else
+ std::cerr << "Not enough positional command line arguments specified!\n"
+ << "Must specify at least " << NumPositionalRequired
+ << " positional arguments.";
+
+ ErrorParsing = true;
+ } else if (!HasUnlimitedPositionals
+ && PositionalVals.size() > PositionalOpts.size()) {
+ if (ProgramName)
+ std::cerr << ProgramName
+ << ": Too many positional arguments specified!\n"
+ << "Can specify at most " << PositionalOpts.size()
+ << " positional arguments: See: " << argv[0] << " --help\n";
+ else
+ std::cerr << "Too many positional arguments specified!\n"
+ << "Can specify at most " << PositionalOpts.size()
+ << " positional arguments.\n";
ErrorParsing = true;
-
} else if (ConsumeAfterOpt == 0) {
// Positional args have already been handled if ConsumeAfter is specified...
void operator=(bool OptionWasSpecified) {
if (OptionWasSpecified) {
std::cerr << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
- << PACKAGE_VERSION << " (see http://llvm.cs.uiuc.edu/)\n";
+ << PACKAGE_VERSION << " (see http://llvm.org/)";
+#ifndef NDEBUG
+ std::cerr << " DEBUG BUILD\n";
+#else
+ std::cerr << "\n";
+#endif
getOpts().clear(); // Don't bother making option dtors remove from map.
exit(1);
}
HelpPrinter HiddenPrinter(true);
cl::opt<HelpPrinter, true, parser<bool> >
-HOp("help", cl::desc("display available options (--help-hidden for more)"),
+HOp("help", cl::desc("Display available options (--help-hidden for more)"),
cl::location(NormalPrinter), cl::ValueDisallowed);
cl::opt<HelpPrinter, true, parser<bool> >
-HHOp("help-hidden", cl::desc("display all available options"),
+HHOp("help-hidden", cl::desc("Display all available options"),
cl::location(HiddenPrinter), cl::Hidden, cl::ValueDisallowed);
// Define the --version option that prints out the LLVM version for the tool
VersionPrinter VersionPrinterInstance;
cl::opt<VersionPrinter, true, parser<bool> >
-VersOp("version", cl::desc("display the version"),
+VersOp("version", cl::desc("Display the version of this program"),
cl::location(VersionPrinterInstance), cl::ValueDisallowed);