cli: if cppcheck premium edition is executed then allow a special option --premium=<option> also

This commit is contained in:
Daniel Marjamäki 2022-08-24 08:46:35 +02:00
parent 19e9712762
commit 8c0dfea472
2 changed files with 42 additions and 12 deletions

View File

@ -608,6 +608,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
} }
} }
// Special Cppcheck Premium options
else if (std::strncmp(argv[i], "--premium=", 10) == 0 && isCppcheckPremium()) {
if (!mSettings->premiumArgs.size())
mSettings->premiumArgs += " ";
mSettings->premiumArgs += "--" + std::string(argv[i] + 10);
}
// --project // --project
else if (std::strncmp(argv[i], "--project=", 10) == 0) { else if (std::strncmp(argv[i], "--project=", 10) == 0) {
mSettings->checkAllConfigurations = false; // Can be overridden with --max-configs or --force mSettings->checkAllConfigurations = false; // Can be overridden with --max-configs or --force
@ -1177,17 +1184,32 @@ void CmdLineParser::printHelp()
" * unspecified\n" " * unspecified\n"
" Unknown type sizes\n" " Unknown type sizes\n"
" --plist-output=<path>\n" " --plist-output=<path>\n"
" Generate Clang-plist output files in folder.\n" " Generate Clang-plist output files in folder.\n";
" -q, --quiet Do not show progress reports.\n"
" -rp=<paths>, --relative-paths=<paths>\n" if (isCppcheckPremium()) {
" Use relative paths in output. When given, <paths> are\n" std::cout << " --premium=<option>\n"
" used as base. You can separate multiple paths by ';'.\n" << " Coding standards:\n"
" Otherwise path where source files are searched is used.\n" << " * autosar Autosar (partial)\n"
" We use string comparison to create relative paths, so\n" << " * cert-c-2016 Cert C 2016 checking\n"
" using e.g. ~ for home folder does not work. It is\n" << " * cert-c++-2016 Cert C++ 2016 checking (partial)\n"
" currently only possible to apply the base paths to\n" << " * misra-c-2012 Misra C 2012\n"
" files that are on a lower level in the directory tree.\n" << " * misra-c++-2008 Misra C++ 2008 (partial)\n"
" --report-progress Report progress messages while checking a file.\n" << " Other:\n"
<< " * bughunting Soundy analysis\n"
<< " * cert-c-int-precision=BITS integer precision to use in Cert C analysis.\n";
}
std::cout <<
" -q, --quiet Do not show progress reports.\n"
" -rp=<paths>, --relative-paths=<paths>\n"
" Use relative paths in output. When given, <paths> are\n"
" used as base. You can separate multiple paths by ';'.\n"
" Otherwise path where source files are searched is used.\n"
" We use string comparison to create relative paths, so\n"
" using e.g. ~ for home folder does not work. It is\n"
" currently only possible to apply the base paths to\n"
" files that are on a lower level in the directory tree.\n"
" --report-progress Report progress messages while checking a file.\n"
#ifdef HAVE_RULES #ifdef HAVE_RULES
" --rule=<rule> Match regular expression.\n" " --rule=<rule> Match regular expression.\n"
" --rule-file=<file> Use given rule file. For more information, see:\n" " --rule-file=<file> Use given rule file. For more information, see:\n"
@ -1292,3 +1314,9 @@ void CmdLineParser::printHelp()
" * pcre -- rules.\n" " * pcre -- rules.\n"
" * qt -- used in GUI\n"; " * qt -- used in GUI\n";
} }
bool CmdLineParser::isCppcheckPremium() const {
if (mSettings->cppcheckCfgProductName.empty())
mSettings->loadCppcheckCfg();
return mSettings->cppcheckCfgProductName.compare(0, 16, "Cppcheck Premium") == 0;
}

View File

@ -98,7 +98,7 @@ protected:
/** /**
* Print help text to the console. * Print help text to the console.
*/ */
static void printHelp(); void printHelp();
/** /**
* Print message (to stdout). * Print message (to stdout).
@ -111,6 +111,8 @@ protected:
static void printError(const std::string &message); static void printError(const std::string &message);
private: private:
bool isCppcheckPremium() const;
std::vector<std::string> mPathNames; std::vector<std::string> mPathNames;
std::vector<std::string> mIgnoredPaths; std::vector<std::string> mIgnoredPaths;
Settings *mSettings; Settings *mSettings;