CLI: Add --output-file flag so results can be written to file directly.

This commit is contained in:
Daniel Marjamäki 2017-05-30 15:04:28 +02:00
parent 318b998742
commit 1f48b082d1
4 changed files with 20 additions and 3 deletions

View File

@ -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
else if (std::strncmp(argv[i], "--plist-output=", 15) == 0) {
_settings->plistOutput = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 15));
@ -923,6 +927,7 @@ void CmdLineParser::PrintHelp()
" distributed with Cppcheck is loaded automatically.\n"
" For more information about library files, read the\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"
" Studio Solution (*.sln), Visual Studio Project\n"
" (*.vcxproj), or compile database\n"

View File

@ -78,7 +78,7 @@
/*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout;
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)
time1 = std::time(0);
if (!settings.outputFile.empty()) {
errorOutput = fopen(settings.outputFile.c_str(), "wt");
}
if (settings.xml) {
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version));
}
@ -923,7 +927,7 @@ void CppCheckExecutor::reportErr(const std::string &errmsg)
return;
_errorList.insert(errmsg);
std::cerr << errmsg << std::endl;
std::fprintf(errorOutput, "%s\n", errmsg.c_str());
}
void CppCheckExecutor::reportOut(const std::string &outmsg)

View File

@ -176,6 +176,11 @@ private:
*/
static FILE* exceptionOutput;
/**
* Error output (default stderr)
*/
FILE* errorOutput;
/**
* Has --errorlist been given?
*/

View File

@ -132,7 +132,10 @@ public:
/** @brief Paths used as base for conversion to relative paths. */
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;
/** @brief write XML results (--xml) */