diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 2d75c59cf20..e53ac06a3cd 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -1931,6 +1931,15 @@ bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, /// option category to display in the -help output. void HideUnrelatedOptions(cl::OptionCategory &Category); +/// \brief Mark all options not part of the categories as cl::ReallyHidden. +/// +/// \param Categories the categories of options to keep displaying. +/// +/// Some tools (like clang-format) like to be able to hide all options that are +/// not specific to the tool. This function allows a tool to specify a single +/// option category to display in the -help output. +void HideUnrelatedOptions(SmallVectorImpl &Categories); + } // End namespace cl } // End namespace llvm diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 87f2261def5..4cd6f0c5f0a 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -1861,6 +1861,20 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category) { } } +void cl::HideUnrelatedOptions( + SmallVectorImpl &Categories) { + auto CategoriesBegin = Categories.begin(); + auto CategoriesEnd = Categories.end(); + StringMap Options; + cl::getRegisteredOptions(Options); + for (auto &I : Options) { + if (std::find(CategoriesBegin, CategoriesEnd, I.second->Category) == + CategoriesEnd && + I.second->Category != &GenericCategory) + I.second->setHiddenFlag(cl::ReallyHidden); + } +} + void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview) { llvm::cl::ParseCommandLineOptions(argc, argv, Overview);