forked from OSchip/llvm-project
[llvm] [CommandLine] Do not suggest really hidden opts in nearest lookup
Skip 'really hidden' options when performing lookup of the nearest option when invalid option was passed. Since these options aren't even documented in --help-hidden, it seems inconsistent to suggest them to users. This fixes clang-tools-extra test failures due to unexpected suggestions when linking the tools to LLVM dylib (that provides more options than the subset of LLVM libraries linked directly). Differential Revision: https://reviews.llvm.org/D82001
This commit is contained in:
parent
2956cc50f3
commit
5c621900a6
|
@ -592,6 +592,10 @@ static Option *LookupNearestOption(StringRef Arg,
|
|||
ie = OptionsMap.end();
|
||||
it != ie; ++it) {
|
||||
Option *O = it->second;
|
||||
// Do not suggest really hidden options (not shown in any help).
|
||||
if (O->getOptionHiddenFlag() == ReallyHidden)
|
||||
continue;
|
||||
|
||||
SmallVector<StringRef, 16> OptionNames;
|
||||
O->getExtraOptionNames(OptionNames);
|
||||
if (O->hasArgStr())
|
||||
|
|
|
@ -1735,6 +1735,29 @@ TEST(CommandLineTest, OptionErrorMessageSuggest) {
|
|||
cl::ResetAllOptionOccurrences();
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, OptionErrorMessageSuggestNoHidden) {
|
||||
// We expect that 'really hidden' option do not show up in option
|
||||
// suggestions.
|
||||
cl::ResetCommandLineParser();
|
||||
|
||||
StackOption<bool> OptLong("aluminium", cl::desc("Some long option"));
|
||||
StackOption<bool> OptLong2("aluminum", cl::desc("Bad option"),
|
||||
cl::ReallyHidden);
|
||||
|
||||
const char *args[] = {"prog", "--alumnum"};
|
||||
|
||||
std::string Errs;
|
||||
raw_string_ostream OS(Errs);
|
||||
|
||||
EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
|
||||
OS.flush();
|
||||
EXPECT_FALSE(Errs.find("prog: Did you mean '--aluminium'?\n") ==
|
||||
std::string::npos);
|
||||
Errs.clear();
|
||||
|
||||
cl::ResetAllOptionOccurrences();
|
||||
}
|
||||
|
||||
TEST(CommandLineTest, Callback) {
|
||||
cl::ResetCommandLineParser();
|
||||
|
||||
|
|
Loading…
Reference in New Issue