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:
parent
50dba88077
commit
dcc241a2b4
|
@ -60,6 +60,7 @@ CmdLineParser::CmdLineParser(Settings *settings)
|
||||||
, _showHelp(false)
|
, _showHelp(false)
|
||||||
, _showVersion(false)
|
, _showVersion(false)
|
||||||
, _showErrorMessages(false)
|
, _showErrorMessages(false)
|
||||||
|
, _exitAfterPrint(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
if (strcmp(argv[i], "--version") == 0)
|
if (strcmp(argv[i], "--version") == 0)
|
||||||
{
|
{
|
||||||
_showVersion = true;
|
_showVersion = true;
|
||||||
|
_exitAfterPrint = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Flag used for various purposes during debugging
|
// Flag used for various purposes during debugging
|
||||||
|
@ -365,6 +367,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
//_cppcheck->getErrorMessages();
|
//_cppcheck->getErrorMessages();
|
||||||
_showErrorMessages = true;
|
_showErrorMessages = true;
|
||||||
_settings->_xml = true;
|
_settings->_xml = true;
|
||||||
|
_exitAfterPrint = true;
|
||||||
return 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)
|
while (doc2.find("\n\n\n") != std::string::npos)
|
||||||
doc2.erase(doc2.find("\n\n\n"), 1);
|
doc2.erase(doc2.find("\n\n\n"), 1);
|
||||||
std::cout << doc2;
|
std::cout << doc2;
|
||||||
|
_exitAfterPrint = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,6 +463,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
{
|
{
|
||||||
_pathnames.clear();
|
_pathnames.clear();
|
||||||
_showHelp = true;
|
_showHelp = true;
|
||||||
|
_exitAfterPrint = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,14 @@ public:
|
||||||
return _showHelp;
|
return _showHelp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return if we should exit after printing version, help etc.
|
||||||
|
*/
|
||||||
|
bool ExitAfterPrinting() const
|
||||||
|
{
|
||||||
|
return _exitAfterPrint;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,6 +109,7 @@ private:
|
||||||
bool _showHelp;
|
bool _showHelp;
|
||||||
bool _showVersion;
|
bool _showVersion;
|
||||||
bool _showErrorMessages;
|
bool _showErrorMessages;
|
||||||
|
bool _exitAfterPrint;
|
||||||
std::vector<std::string> _pathnames;
|
std::vector<std::string> _pathnames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
|
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
|
||||||
cppcheck->getErrorMessages();
|
cppcheck->getErrorMessages();
|
||||||
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
||||||
std::exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parser.ExitAfterPrinting())
|
||||||
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all include paths exist
|
// Check that all include paths exist
|
||||||
|
|
Loading…
Reference in New Issue