Index: include/clang/Tooling/CommonOptionsParser.h =================================================================== --- include/clang/Tooling/CommonOptionsParser.h +++ include/clang/Tooling/CommonOptionsParser.h @@ -72,6 +72,22 @@ /// This constructor exits program in case of error. CommonOptionsParser(int &argc, const char **argv, llvm::cl::OptionCategory &Category, + const char *Overview = nullptr) + : CommonOptionsParser (argc, argv, Category, llvm::cl::OneOrMore, Overview) {} + + /// \brief Parses command-line, initializes a compilation database. + /// + /// This constructor can change argc and argv contents, e.g. consume + /// command-line options used for creating FixedCompilationDatabase. + /// + /// All options not belonging to \p Category become hidden. + /// + /// I also allows calls to set the required number of positional parameters. + /// + /// This constructor exits program in case of error. + CommonOptionsParser(int &argc, const char **argv, + llvm::cl::OptionCategory &Category, + enum llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview = nullptr); /// Returns a reference to the loaded compilations database. Index: lib/Tooling/CommonOptionsParser.cpp =================================================================== --- lib/Tooling/CommonOptionsParser.cpp +++ lib/Tooling/CommonOptionsParser.cpp @@ -94,6 +94,7 @@ CommonOptionsParser::CommonOptionsParser(int &argc, const char **argv, cl::OptionCategory &Category, + enum llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview) { static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden); @@ -101,7 +102,7 @@ cl::Optional, cl::cat(Category)); static cl::list SourcePaths( - cl::Positional, cl::desc(" [... ]"), cl::OneOrMore, + cl::Positional, cl::desc(" [... ]"), OccurrencesFlag, cl::cat(Category)); static cl::list ArgsAfter( @@ -120,6 +121,8 @@ argv)); cl::ParseCommandLineOptions(argc, argv, Overview); SourcePathList = SourcePaths; + if (OccurrencesFlag == cl::ZeroOrMore && SourcePathList.empty()) + return; if (!Compilations) { std::string ErrorMessage; if (!BuildPath.empty()) {