Don't print "files not found" after showing help.

Fix ticket #2496 (Is error reporting for an unneeded parameter wrong?)

There are several command line options / commands after which we
don't want Cppcheck to even try to open any files. Eg. printing
help or listing errors. So add new attribute for CmdLineParser to
track use of these options and exit before checking files when
the attribute is set.
This commit is contained in:
Kimmo Varis 2011-01-27 10:30:53 +02:00
parent 50dba88077
commit dcc241a2b4
3 changed files with 17 additions and 1 deletions

View File

@ -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;
}

View File

@ -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<std::string> _pathnames;
};

View File

@ -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