Don't stop processing cmd line after --errorlist.

Ticket #2441 (Parsing of command line arguments breaks after --errorlist)

Instead of stopping processing command line options after
--errorlist process them all. This way e.g. --verbose can be given
also after the --errorlist.
This commit is contained in:
Kimmo Varis 2011-01-27 11:14:08 +02:00
parent dcc241a2b4
commit a794edd934
3 changed files with 37 additions and 6 deletions

View File

@ -364,11 +364,9 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// print all possible error messages.. // print all possible error messages..
else if (strcmp(argv[i], "--errorlist") == 0) else if (strcmp(argv[i], "--errorlist") == 0)
{ {
//_cppcheck->getErrorMessages();
_showErrorMessages = true; _showErrorMessages = true;
_settings->_xml = true; _settings->_xml = true;
_exitAfterPrint = true; _exitAfterPrint = true;
return true;
} }
// documentation.. // documentation..
@ -491,15 +489,17 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
PrintMessage("--test-2-pass doesn't work with -j option yet."); PrintMessage("--test-2-pass doesn't work with -j option yet.");
} }
if (argc <= 1) if (argc <= 1)
_showHelp = true; _showHelp = true;
if (_showHelp) if (_showHelp)
{ {
PrintHelp(); PrintHelp();
return true;
} }
else if (_pathnames.empty())
// Print error only if we have "real" command and expect files
if (!_exitAfterPrint && _pathnames.empty())
{ {
PrintMessage("cppcheck: No C or C++ source files found."); PrintMessage("cppcheck: No C or C++ source files found.");
return false; return false;

View File

@ -45,10 +45,9 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
if (success) if (success)
{ {
if (parser.GetShowVersion()) if (parser.GetShowVersion() && !parser.GetShowErrorMessages())
{ {
std::cout << "Cppcheck " << cppcheck->version() << std::endl; std::cout << "Cppcheck " << cppcheck->version() << std::endl;
return true;
} }
if (parser.GetShowErrorMessages()) if (parser.GetShowErrorMessages())

View File

@ -77,6 +77,9 @@ private:
TEST_CASE(templatesGcc); TEST_CASE(templatesGcc);
TEST_CASE(templatesVs); TEST_CASE(templatesVs);
TEST_CASE(xml); TEST_CASE(xml);
TEST_CASE(errorlist1);
TEST_CASE(errorlistverbose1)
TEST_CASE(errorlistverbose2)
TEST_CASE(unknownParam); TEST_CASE(unknownParam);
} }
@ -535,6 +538,35 @@ private:
ASSERT(settings._xml); ASSERT(settings._xml);
} }
void errorlist1()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(2, argv));
}
void errorlistverbose1()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--verbose", "--errorlist"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose);
}
void errorlistverbose2()
{
REDIRECT;
const char *argv[] = {"cppcheck", "--errorlist", "--verbose"};
Settings settings;
CmdLineParser parser(&settings);
ASSERT(parser.ParseFromArgs(3, argv));
ASSERT(settings._verbose);
}
void unknownParam() void unknownParam()
{ {
REDIRECT; REDIRECT;