From c2ef08ccf51749f039cf143c07b8ffcd2b973cdd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 31 Jan 2002 00:42:56 +0000 Subject: [PATCH] If an invalid alternative is listed for an argument, print the valid options llvm-svn: 1604 --- llvm/lib/Support/CommandLine.cpp | 15 ++++++++++++--- llvm/support/lib/Support/CommandLine.cpp | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 549f42c4e3be..d3966279b4fa 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -34,7 +34,7 @@ static map &getOpts() { static void AddArgument(const string &ArgName, Option *Opt) { if (getOpts().find(ArgName) != getOpts().end()) { cerr << "CommandLine Error: Argument '" << ArgName - << "' specified more than once!\n"; + << "' defined more than once!\n"; } else { // Add argument to the argument map! getOpts().insert(std::make_pair(ArgName, Opt)); @@ -335,8 +335,17 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned i; for (i = 0; i < ValueMap.size(); ++i) if (ValueMap[i].first == Arg) break; - if (i == ValueMap.size()) - return error(": unrecognized alternative '"+Arg+"'!"); + + if (i == ValueMap.size()) { + string Alternatives; + for (i = 0; i < ValueMap.size(); ++i) { + if (i) Alternatives += ", "; + Alternatives += ValueMap[i].first; + } + + return error(": unrecognized alternative '" + Arg + + "'! Alternatives are: " + Alternatives); + } Value = ValueMap[i].second.first; return false; } diff --git a/llvm/support/lib/Support/CommandLine.cpp b/llvm/support/lib/Support/CommandLine.cpp index 549f42c4e3be..d3966279b4fa 100644 --- a/llvm/support/lib/Support/CommandLine.cpp +++ b/llvm/support/lib/Support/CommandLine.cpp @@ -34,7 +34,7 @@ static map &getOpts() { static void AddArgument(const string &ArgName, Option *Opt) { if (getOpts().find(ArgName) != getOpts().end()) { cerr << "CommandLine Error: Argument '" << ArgName - << "' specified more than once!\n"; + << "' defined more than once!\n"; } else { // Add argument to the argument map! getOpts().insert(std::make_pair(ArgName, Opt)); @@ -335,8 +335,17 @@ bool EnumValueBase::handleOccurance(const char *ArgName, const string &Arg) { unsigned i; for (i = 0; i < ValueMap.size(); ++i) if (ValueMap[i].first == Arg) break; - if (i == ValueMap.size()) - return error(": unrecognized alternative '"+Arg+"'!"); + + if (i == ValueMap.size()) { + string Alternatives; + for (i = 0; i < ValueMap.size(); ++i) { + if (i) Alternatives += ", "; + Alternatives += ValueMap[i].first; + } + + return error(": unrecognized alternative '" + Arg + + "'! Alternatives are: " + Alternatives); + } Value = ValueMap[i].second.first; return false; }