1 // Copyright (C) 2019 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "command_line_utils.h" 16 17 #include <llvm/ADT/SmallVector.h> 18 #include <llvm/ADT/StringMap.h> 19 #include <llvm/Support/CommandLine.h> 20 21 #include <algorithm> 22 23 namespace header_checker { 24 namespace utils { 25 26 IsOptionInCategory(const llvm::cl::Option & option,const llvm::cl::OptionCategory & category)27static bool IsOptionInCategory(const llvm::cl::Option &option, 28 const llvm::cl::OptionCategory &category) { 29 const llvm::SmallVectorImpl<llvm::cl::OptionCategory *> &categories = 30 option.Categories; 31 auto iter = std::find(categories.begin(), categories.end(), &category); 32 return iter != categories.end(); 33 } 34 35 HideIrrelevantCommandLineOptions(const llvm::cl::OptionCategory & category)36void HideIrrelevantCommandLineOptions( 37 const llvm::cl::OptionCategory &category) { 38 llvm::StringMap<llvm::cl::Option *> &map = llvm::cl::getRegisteredOptions(); 39 for (llvm::StringMapEntry<llvm::cl::Option *> &p : map) { 40 if (IsOptionInCategory(*p.second, category)) { 41 continue; 42 } 43 if (p.first().startswith("help")) { 44 continue; 45 } 46 p.second->setHiddenFlag(llvm::cl::Hidden); 47 } 48 } 49 50 51 } // namespace utils 52 } // namespace header_checker 53