CLI: Add --output-file flag so results can be written to file directly.
This commit is contained in:
parent
318b998742
commit
1f48b082d1
|
@ -272,6 +272,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write results in file
|
||||||
|
else if (std::strncmp(argv[i], "--output-file=", 14) == 0)
|
||||||
|
_settings->outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14));
|
||||||
|
|
||||||
// Write results in results.plist
|
// Write results in results.plist
|
||||||
else if (std::strncmp(argv[i], "--plist-output=", 15) == 0) {
|
else if (std::strncmp(argv[i], "--plist-output=", 15) == 0) {
|
||||||
_settings->plistOutput = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 15));
|
_settings->plistOutput = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 15));
|
||||||
|
@ -923,6 +927,7 @@ void CmdLineParser::PrintHelp()
|
||||||
" distributed with Cppcheck is loaded automatically.\n"
|
" distributed with Cppcheck is loaded automatically.\n"
|
||||||
" For more information about library files, read the\n"
|
" For more information about library files, read the\n"
|
||||||
" manual.\n"
|
" manual.\n"
|
||||||
|
" --output-file=<file> Write results to file, rather than standard error.\n"
|
||||||
" --project=<file> Run Cppcheck on project. The <file> can be a Visual\n"
|
" --project=<file> Run Cppcheck on project. The <file> can be a Visual\n"
|
||||||
" Studio Solution (*.sln), Visual Studio Project\n"
|
" Studio Solution (*.sln), Visual Studio Project\n"
|
||||||
" (*.vcxproj), or compile database\n"
|
" (*.vcxproj), or compile database\n"
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
/*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout;
|
/*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout;
|
||||||
|
|
||||||
CppCheckExecutor::CppCheckExecutor()
|
CppCheckExecutor::CppCheckExecutor()
|
||||||
: _settings(0), time1(0), errorlist(false)
|
: _settings(0), time1(0), errorOutput(stderr), errorlist(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -808,6 +808,10 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
||||||
if (settings.reportProgress)
|
if (settings.reportProgress)
|
||||||
time1 = std::time(0);
|
time1 = std::time(0);
|
||||||
|
|
||||||
|
if (!settings.outputFile.empty()) {
|
||||||
|
errorOutput = fopen(settings.outputFile.c_str(), "wt");
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.xml) {
|
if (settings.xml) {
|
||||||
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version));
|
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version));
|
||||||
}
|
}
|
||||||
|
@ -923,7 +927,7 @@ void CppCheckExecutor::reportErr(const std::string &errmsg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_errorList.insert(errmsg);
|
_errorList.insert(errmsg);
|
||||||
std::cerr << errmsg << std::endl;
|
std::fprintf(errorOutput, "%s\n", errmsg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheckExecutor::reportOut(const std::string &outmsg)
|
void CppCheckExecutor::reportOut(const std::string &outmsg)
|
||||||
|
|
|
@ -176,6 +176,11 @@ private:
|
||||||
*/
|
*/
|
||||||
static FILE* exceptionOutput;
|
static FILE* exceptionOutput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error output (default stderr)
|
||||||
|
*/
|
||||||
|
FILE* errorOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has --errorlist been given?
|
* Has --errorlist been given?
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -132,7 +132,10 @@ public:
|
||||||
/** @brief Paths used as base for conversion to relative paths. */
|
/** @brief Paths used as base for conversion to relative paths. */
|
||||||
std::vector<std::string> basePaths;
|
std::vector<std::string> basePaths;
|
||||||
|
|
||||||
/** @brief write XML results (--plist-output=<dir>) */
|
/** @brief write results (--output-file=<file>) */
|
||||||
|
std::string outputFile;
|
||||||
|
|
||||||
|
/** @brief plist output (--plist-output=<dir>) */
|
||||||
std::string plistOutput;
|
std::string plistOutput;
|
||||||
|
|
||||||
/** @brief write XML results (--xml) */
|
/** @brief write XML results (--xml) */
|
||||||
|
|
Loading…
Reference in New Issue