mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
Support/CommandLine: Fix LookupNearestOption to also search extra option names.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124124 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ccea167db5
commit
c98d82a7f0
@ -185,7 +185,8 @@ static Option *LookupOption(StringRef &Arg, StringRef &Value,
|
|||||||
/// (after an equal sign) return that as well. This assumes that leading dashes
|
/// (after an equal sign) return that as well. This assumes that leading dashes
|
||||||
/// have already been stripped.
|
/// have already been stripped.
|
||||||
static Option *LookupNearestOption(StringRef Arg,
|
static Option *LookupNearestOption(StringRef Arg,
|
||||||
const StringMap<Option*> &OptionsMap) {
|
const StringMap<Option*> &OptionsMap,
|
||||||
|
const char *&NearestString) {
|
||||||
// Reject all dashes.
|
// Reject all dashes.
|
||||||
if (Arg.empty()) return 0;
|
if (Arg.empty()) return 0;
|
||||||
|
|
||||||
@ -197,11 +198,21 @@ static Option *LookupNearestOption(StringRef Arg,
|
|||||||
unsigned BestDistance = 0;
|
unsigned BestDistance = 0;
|
||||||
for (StringMap<Option*>::const_iterator it = OptionsMap.begin(),
|
for (StringMap<Option*>::const_iterator it = OptionsMap.begin(),
|
||||||
ie = OptionsMap.end(); it != ie; ++it) {
|
ie = OptionsMap.end(); it != ie; ++it) {
|
||||||
unsigned Distance = StringRef(it->second->ArgStr).edit_distance(
|
Option *O = it->second;
|
||||||
Arg, /*AllowReplacements=*/true, /*MaxEditDistance=*/BestDistance);
|
SmallVector<const char*, 16> OptionNames;
|
||||||
if (!Best || Distance < BestDistance) {
|
O->getExtraOptionNames(OptionNames);
|
||||||
Best = it->second;
|
if (O->ArgStr[0])
|
||||||
BestDistance = Distance;
|
OptionNames.push_back(O->ArgStr);
|
||||||
|
|
||||||
|
for (size_t i = 0, e = OptionNames.size(); i != e; ++i) {
|
||||||
|
StringRef Name = OptionNames[i];
|
||||||
|
unsigned Distance = StringRef(Name).edit_distance(
|
||||||
|
Arg, /*AllowReplacements=*/true, /*MaxEditDistance=*/BestDistance);
|
||||||
|
if (!Best || Distance < BestDistance) {
|
||||||
|
Best = O;
|
||||||
|
NearestString = OptionNames[i];
|
||||||
|
BestDistance = Distance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,6 +611,7 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
|
|||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
Option *Handler = 0;
|
Option *Handler = 0;
|
||||||
Option *NearestHandler = 0;
|
Option *NearestHandler = 0;
|
||||||
|
const char *NearestHandlerString = 0;
|
||||||
StringRef Value;
|
StringRef Value;
|
||||||
StringRef ArgName = "";
|
StringRef ArgName = "";
|
||||||
|
|
||||||
@ -677,7 +689,8 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
|
|||||||
// Otherwise, look for the closest available option to report to the user
|
// Otherwise, look for the closest available option to report to the user
|
||||||
// in the upcoming error.
|
// in the upcoming error.
|
||||||
if (Handler == 0 && SinkOpts.empty())
|
if (Handler == 0 && SinkOpts.empty())
|
||||||
NearestHandler = LookupNearestOption(ArgName, Opts);
|
NearestHandler = LookupNearestOption(ArgName, Opts,
|
||||||
|
NearestHandlerString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Handler == 0) {
|
if (Handler == 0) {
|
||||||
@ -685,9 +698,11 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
|
|||||||
errs() << ProgramName << ": Unknown command line argument '"
|
errs() << ProgramName << ": Unknown command line argument '"
|
||||||
<< argv[i] << "'. Try: '" << argv[0] << " -help'\n";
|
<< argv[i] << "'. Try: '" << argv[0] << " -help'\n";
|
||||||
|
|
||||||
// If we know a near match, report it as well.
|
if (NearestHandler) {
|
||||||
errs() << ProgramName << ": Did you mean '-"
|
// If we know a near match, report it as well.
|
||||||
<< NearestHandler->ArgStr << "'?\n";
|
errs() << ProgramName << ": Did you mean '-"
|
||||||
|
<< NearestHandlerString << "'?\n";
|
||||||
|
}
|
||||||
|
|
||||||
ErrorParsing = true;
|
ErrorParsing = true;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user