cmdlineparser: terminate with error message if --append=<filename> fails
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
c317c8979c
commit
d11f18b5df
|
@ -267,8 +267,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->_errorsOnly = true;
|
||||
|
||||
// Append userdefined code to checked source code
|
||||
else if (strncmp(argv[i], "--append=", 9) == 0)
|
||||
_settings->append(9 + argv[i]);
|
||||
else if (strncmp(argv[i], "--append=", 9) == 0) {
|
||||
const std::string filename = 9 + argv[i];
|
||||
if (!_settings->append(filename)) {
|
||||
PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\".");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else if (strncmp(argv[i], "--enable=", 9) == 0) {
|
||||
const std::string errmsg = _settings->addEnabled(argv[i] + 9);
|
||||
|
|
|
@ -118,14 +118,18 @@ bool Settings::isEnabled(const std::string &str) const
|
|||
}
|
||||
|
||||
|
||||
void Settings::append(const std::string &filename)
|
||||
bool Settings::append(const std::string &filename)
|
||||
{
|
||||
_append = "\n";
|
||||
std::ifstream fin(filename.c_str());
|
||||
if (!fin.is_open()) {
|
||||
return false;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(fin, line)) {
|
||||
_append += line + "\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Settings::append() const
|
||||
|
|
|
@ -116,7 +116,7 @@ public:
|
|||
std::list<std::string> _includePaths;
|
||||
|
||||
/** @brief assign append code (--append) */
|
||||
void append(const std::string &filename);
|
||||
bool append(const std::string &filename);
|
||||
|
||||
/** @brief get append code (--append) */
|
||||
std::string append() const;
|
||||
|
|
Loading…
Reference in New Issue