Skip to content

Commit

Permalink
fixed #12811 - added CLI option --filesdir to show the built-in `FI…
Browse files Browse the repository at this point in the history
…LESDIR` / added TODOs
  • Loading branch information
firewave committed Feb 7, 2025
1 parent f447521 commit fd4a955
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
return Result::Exit;
}

if (std::strcmp(argv[i], "--filesdir") == 0) {
#ifdef FILESDIR
mLogger.printRaw(FILESDIR); // TODO: should not include newline
#endif
return Result::Exit;
}

if (std::strcmp(argv[i], "--version") == 0) {
if (!loadCppcheckCfg())
return Result::Fail;
const std::string version = getVersion();
mLogger.printRaw(version);
mLogger.printRaw(version); // TODO: should not include newline
return Result::Exit;
}
}
Expand Down Expand Up @@ -1723,6 +1730,7 @@ void CmdLineParser::printHelp() const
" --file-list=<file> Specify the files to check in a text file. Add one\n"
" filename per line. When file is '-,' the file list will\n"
" be read from standard input.\n"
" --filesdir Print the built-in FILESDIR.\n"
" -f, --force Force checking of all configurations in files. If used\n"
" together with '--max-configs=', the last option is the\n"
" one that is effective.\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ namespace {

void printRaw(const std::string &message) override
{
std::cout << message << std::endl;
std::cout << message << std::endl; // TODO: should not append newline
}
};

Expand Down
11 changes: 11 additions & 0 deletions man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt">
<option>--file-list=&lt;file&gt;</option>
</arg>
<arg choice="opt">
<option>--filesdir</option>
</arg>
<arg choice="opt">
<option>--force</option>
</arg>
Expand Down Expand Up @@ -356,6 +359,14 @@ Example: '-UDEBUG'</para>
<para>Specify the files to check in a text file. One filename per line. When file is -, the file list will be read from standard input.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--filesdir</option>
</term>
<listitem>
<para>Print the built-in FILESDIR.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-f</option>
Expand Down
14 changes: 13 additions & 1 deletion test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TestCmdlineParser : public TestFixture {

void printRaw(const std::string &message) override
{
printInternal(message + '\n');
printInternal(message + '\n'); // TODO: should not append newline
}

std::string str()
Expand Down Expand Up @@ -430,6 +430,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(debugClangOutput);
TEST_CASE(debugXmlMultiple);
TEST_CASE(debugNormalXmlMultiple);
TEST_CASE(filesdir);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -2964,6 +2965,17 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("cppcheck: error: printing debug output in XML format does not support multiple input files.\n", logger->str());
}

void filesdir() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--filesdir"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv));
#ifdef FILESDIR
ASSERT_EQUALS(std::string(FILESDIR) + '\n', logger->str());
#else
ASSERT_EQUALS("", logger->str());
#endif
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down

0 comments on commit fd4a955

Please sign in to comment.