Skip to content

Commit dcc241a

Browse files
committed
Don't print "files not found" after showing help.
Fix ticket cppcheck-opensource#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.
1 parent 50dba88 commit dcc241a

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

cli/cmdlineparser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ CmdLineParser::CmdLineParser(Settings *settings)
6060
, _showHelp(false)
6161
, _showVersion(false)
6262
, _showErrorMessages(false)
63+
, _exitAfterPrint(false)
6364
{
6465
}
6566

@@ -75,6 +76,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
7576
if (strcmp(argv[i], "--version") == 0)
7677
{
7778
_showVersion = true;
79+
_exitAfterPrint = true;
7880
return true;
7981
}
8082
// Flag used for various purposes during debugging
@@ -365,6 +367,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
365367
//_cppcheck->getErrorMessages();
366368
_showErrorMessages = true;
367369
_settings->_xml = true;
370+
_exitAfterPrint = true;
368371
return true;
369372
}
370373

@@ -383,6 +386,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
383386
while (doc2.find("\n\n\n") != std::string::npos)
384387
doc2.erase(doc2.find("\n\n\n"), 1);
385388
std::cout << doc2;
389+
_exitAfterPrint = true;
386390
return true;
387391
}
388392

@@ -459,6 +463,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
459463
{
460464
_pathnames.clear();
461465
_showHelp = true;
466+
_exitAfterPrint = true;
462467
break;
463468
}
464469

cli/cmdlineparser.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ class CmdLineParser
8484
return _showHelp;
8585
}
8686

87+
/**
88+
* Return if we should exit after printing version, help etc.
89+
*/
90+
bool ExitAfterPrinting() const
91+
{
92+
return _exitAfterPrint;
93+
}
94+
8795
protected:
8896

8997
/**
@@ -101,6 +109,7 @@ class CmdLineParser
101109
bool _showHelp;
102110
bool _showVersion;
103111
bool _showErrorMessages;
112+
bool _exitAfterPrint;
104113
std::vector<std::string> _pathnames;
105114
};
106115

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
5757
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
5858
cppcheck->getErrorMessages();
5959
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
60-
std::exit(0);
6160
}
61+
62+
if (parser.ExitAfterPrinting())
63+
std::exit(0);
6264
}
6365

6466
// Check that all include paths exist

0 commit comments

Comments
 (0)