diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index af6e677af..0d9ded344 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -60,6 +60,7 @@ CmdLineParser::CmdLineParser(Settings *settings) , _showHelp(false) , _showVersion(false) , _showErrorMessages(false) + , _exitAfterPrint(false) { } @@ -75,6 +76,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) if (strcmp(argv[i], "--version") == 0) { _showVersion = true; + _exitAfterPrint = true; return true; } // Flag used for various purposes during debugging @@ -365,6 +367,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) //_cppcheck->getErrorMessages(); _showErrorMessages = true; _settings->_xml = true; + _exitAfterPrint = true; return true; } @@ -383,6 +386,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) while (doc2.find("\n\n\n") != std::string::npos) doc2.erase(doc2.find("\n\n\n"), 1); std::cout << doc2; + _exitAfterPrint = true; return true; } @@ -459,6 +463,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) { _pathnames.clear(); _showHelp = true; + _exitAfterPrint = true; break; } diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 60fccb93b..7a60e24a6 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -84,6 +84,14 @@ public: return _showHelp; } + /** + * Return if we should exit after printing version, help etc. + */ + bool ExitAfterPrinting() const + { + return _exitAfterPrint; + } + protected: /** @@ -101,6 +109,7 @@ private: bool _showHelp; bool _showVersion; bool _showErrorMessages; + bool _exitAfterPrint; std::vector _pathnames; }; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 4885357e6..efc6ceadc 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -57,8 +57,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version); cppcheck->getErrorMessages(); std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl; - std::exit(0); } + + if (parser.ExitAfterPrinting()) + std::exit(0); } // Check that all include paths exist