From b22daabd2e00cf3f0b9ff229b2f31cbb839217fe Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 31 Aug 2024 15:43:02 +0200 Subject: [PATCH] added `--file-filter=+` to treat provided input files as filter [skip ci] --- cli/cmdlineparser.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 51eded9cb71..f6e63f8a625 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -369,6 +369,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a ImportProject project; + bool inputAsFilter = false; bool executorAuto = true; int8_t logMissingInclude{0}; @@ -711,6 +712,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a mLogger.printError("Failed: --file-filter=-"); return Result::Fail; } + } if (std::strcmp(filter, "+") == 0) { + inputAsFilter = true; } else { mSettings.fileFilters.emplace_back(filter); } @@ -1441,11 +1444,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a //mLogger.printMessage("whole program analysis requires --cppcheck-build-dir to be active with -j."); } - if (!mPathNames.empty() && project.projectType != ImportProject::Type::NONE) { + if (!inputAsFilter && !mPathNames.empty() && project.projectType != ImportProject::Type::NONE) { mLogger.printError("--project cannot be used in conjunction with source files."); return Result::Fail; } + if (inputAsFilter) { + // these will not be resolved and be used literally + mSettings.fileFilters.insert(mSettings.fileFilters.cend(), mPathNames.cbegin(), mPathNames.cend()); + mPathNames.clear(); + } + // Print error only if we have "real" command and expect files if (mPathNames.empty() && project.guiProject.pathNames.empty() && project.fileSettings.empty()) { // TODO: this message differs from the one reported in fillSettingsFromArgs()