Author: alexfh Date: Mon Aug 17 05:03:27 2015 New Revision: 245205 URL: http://llvm.org/viewvc/llvm-project?rev=245205&view=rev Log: [clang-tidy] Allow use of -list-checks option without need to pass source files.
Initialize CommonOptionsParser with ZeroOrOne NumOccurrenceFlag so callers can pass -list-checks without the need to pass additional positional parameters, then add dummy file if none were supplied. http://reviews.llvm.org/D12070 Patch by Don Hinton! Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=245205&r1=245204&r2=245205&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Aug 17 05:03:27 2015 @@ -262,17 +262,21 @@ static std::unique_ptr<ClangTidyOptionsP } static int clangTidyMain(int argc, const char **argv) { - CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory); + CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, + cl::ZeroOrMore); auto OptionsProvider = createOptionsProvider(); if (!OptionsProvider) return 1; - std::string FileName = OptionsParser.getSourcePathList().front(); + StringRef FileName("dummy"); + auto PathList = OptionsParser.getSourcePathList(); + if (!PathList.empty()) { + FileName = OptionsParser.getSourcePathList().front(); + } ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName); std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions); - // FIXME: Allow using --list-checks without positional arguments. if (ListChecks) { llvm::outs() << "Enabled checks:"; for (auto CheckName : EnabledChecks) @@ -283,8 +287,9 @@ static int clangTidyMain(int argc, const if (DumpConfig) { EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions); - llvm::outs() << configurationAsText(ClangTidyOptions::getDefaults() - .mergeWith(EffectiveOptions)) + llvm::outs() << configurationAsText( + ClangTidyOptions::getDefaults().mergeWith( + EffectiveOptions)) << "\n"; return 0; } @@ -295,12 +300,18 @@ static int clangTidyMain(int argc, const return 1; } + if (PathList.empty()) { + llvm::errs() << "Error: no input files specified.\n"; + llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); + return 1; + } + ProfileData Profile; std::vector<ClangTidyError> Errors; ClangTidyStats Stats = runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(), - OptionsParser.getSourcePathList(), &Errors, + PathList, &Errors, EnableCheckProfile ? &Profile : nullptr); bool FoundErrors = std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) { Modified: clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp?rev=245205&r1=245204&r2=245205&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/validate-check-names.cpp Mon Aug 17 05:03:27 2015 @@ -1,2 +1,2 @@ // Check names may only contain alphanumeric characters, '-', '_', and '.'. -// RUN: clang-tidy -checks=* -list-checks - -- | grep '^ ' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$' +// RUN: clang-tidy -checks=* -list-checks | grep '^ ' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits