Add new HideUnrelatedOptions API that takes a SmallVectorImpl.
authorChris Bieneman <beanz@apple.com>
Mon, 26 Jan 2015 21:57:29 +0000 (21:57 +0000)
committerChris Bieneman <beanz@apple.com>
Mon, 26 Jan 2015 21:57:29 +0000 (21:57 +0000)
Need a new API for clang-modernize that allows specifying a list of option categories to remain visible. This will allow clang-modernize to move off getRegisteredOptions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227140 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/CommandLine.h
lib/Support/CommandLine.cpp

index 2d75c59cf207612fb487fb4f0b0a26f795894c79..e53ac06a3cde85dd606a76f4e8aebaed7ee88f66 100644 (file)
@@ -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<cl::OptionCategory *> &Categories);
+
 } // End namespace cl
 
 } // End namespace llvm
index 87f2261def515cd43947508d7484300ec7d3082f..4cd6f0c5f0a398fd398bca744b06f61201044174 100644 (file)
@@ -1861,6 +1861,20 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category) {
   }
 }
 
+void cl::HideUnrelatedOptions(
+    SmallVectorImpl<cl::OptionCategory *> &Categories) {
+  auto CategoriesBegin = Categories.begin();
+  auto CategoriesEnd = Categories.end();
+  StringMap<cl::Option *> 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);