llvm.org GIT mirror llvm / f045681
Adding a new cl::HideUnrelatedOptions API to allow clang to migrate off cl::getRegisteredOptions. Summary: cl::getRegisteredOptions really exposes some of the innards of how command line parsing is implemented. Exposing new APIs that allow us to disentangle client code from implementation details will allow us to make more extensive changes to command line parsing. Reviewers: chandlerc, dexonsmith, beanz Reviewed By: dexonsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7100 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226729 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 5 years ago
3 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
18881888 SmallVectorImpl &Argv,
18891889 bool MarkEOLs = false);
18901890
1891 /// \brief Mark all options not part of this category as cl::ReallyHidden.
1892 ///
1893 /// \param Category the category of options to keep displaying
1894 ///
1895 /// Some tools (like clang-format) like to be able to hide all options that are
1896 /// not specific to the tool. This function allows a tool to specify a single
1897 /// option category to display in the -help output.
1898 void HideUnrelatedOptions(cl::OptionCategory &Category);
1899
18911900 } // End namespace cl
18921901
18931902 } // End namespace llvm
18251825 void cl::getRegisteredOptions(StringMap
18261826 // Get all the options.
18271827 SmallVector
1828 SmallVector
1828 SmallVector
18291829 assert(Map.size() == 0 && "StringMap must be empty");
18301830 GetOptionInfo(PositionalOpts, SinkOpts, Map);
18311831 return;
18321832 }
18331833
1834 void cl::HideUnrelatedOptions(cl::OptionCategory &Category) {
1835 StringMap Options;
1836 cl::getRegisteredOptions(Options);
1837 for (auto &I : Options) {
1838 if (I.second->Category != &Category && I.first() != "help" &&
1839 I.first() != "version")
1840 I.second->setHiddenFlag(cl::ReallyHidden);
1841 }
1842 }
1843
18341844 void LLVMParseCommandLineOptions(int argc, const char *const *argv,
18351845 const char *Overview) {
18361846 llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
229229 testAliasRequired(array_lengthof(opts2), opts2);
230230 }
231231
232 TEST(CommandLineTest, HideUnrelatedOptions) {
233 cl::opt TestOption1("test-option-1");
234 cl::opt TestOption2("test-option-2", cl::cat(TestCategory));
235
236 cl::HideUnrelatedOptions(TestCategory);
237
238 ASSERT_EQ(cl::ReallyHidden, TestOption1.getOptionHiddenFlag())
239 << "Failed to hide extra option.";
240 ASSERT_EQ(cl::NotHidden, TestOption2.getOptionHiddenFlag())
241 << "Hid extra option that should be visable.";
242 }
232243
233244 } // anonymous namespace