Skip to content

Commit fd4a955

Browse files
committed
fixed #12811 - added CLI option --filesdir to show the built-in FILESDIR / added TODOs
1 parent f447521 commit fd4a955

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

cli/cmdlineparser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,18 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
422422
return Result::Exit;
423423
}
424424

425+
if (std::strcmp(argv[i], "--filesdir") == 0) {
426+
#ifdef FILESDIR
427+
mLogger.printRaw(FILESDIR); // TODO: should not include newline
428+
#endif
429+
return Result::Exit;
430+
}
431+
425432
if (std::strcmp(argv[i], "--version") == 0) {
426433
if (!loadCppcheckCfg())
427434
return Result::Fail;
428435
const std::string version = getVersion();
429-
mLogger.printRaw(version);
436+
mLogger.printRaw(version); // TODO: should not include newline
430437
return Result::Exit;
431438
}
432439
}
@@ -1723,6 +1730,7 @@ void CmdLineParser::printHelp() const
17231730
" --file-list=<file> Specify the files to check in a text file. Add one\n"
17241731
" filename per line. When file is '-,' the file list will\n"
17251732
" be read from standard input.\n"
1733+
" --filesdir Print the built-in FILESDIR.\n"
17261734
" -f, --force Force checking of all configurations in files. If used\n"
17271735
" together with '--max-configs=', the last option is the\n"
17281736
" one that is effective.\n"

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace {
241241

242242
void printRaw(const std::string &message) override
243243
{
244-
std::cout << message << std::endl;
244+
std::cout << message << std::endl; // TODO: should not append newline
245245
}
246246
};
247247

man/cppcheck.1.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
123123
<arg choice="opt">
124124
<option>--file-list=&lt;file&gt;</option>
125125
</arg>
126+
<arg choice="opt">
127+
<option>--filesdir</option>
128+
</arg>
126129
<arg choice="opt">
127130
<option>--force</option>
128131
</arg>
@@ -356,6 +359,14 @@ Example: '-UDEBUG'</para>
356359
<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>
357360
</listitem>
358361
</varlistentry>
362+
<varlistentry>
363+
<term>
364+
<option>--filesdir</option>
365+
</term>
366+
<listitem>
367+
<para>Print the built-in FILESDIR.</para>
368+
</listitem>
369+
</varlistentry>
359370
<varlistentry>
360371
<term>
361372
<option>-f</option>

test/testcmdlineparser.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class TestCmdlineParser : public TestFixture {
6565

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

7171
std::string str()
@@ -430,6 +430,7 @@ class TestCmdlineParser : public TestFixture {
430430
TEST_CASE(debugClangOutput);
431431
TEST_CASE(debugXmlMultiple);
432432
TEST_CASE(debugNormalXmlMultiple);
433+
TEST_CASE(filesdir);
433434

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

2968+
void filesdir() {
2969+
REDIRECT;
2970+
const char * const argv[] = {"cppcheck", "--filesdir"};
2971+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parser->parseFromArgs(2, argv));
2972+
#ifdef FILESDIR
2973+
ASSERT_EQUALS(std::string(FILESDIR) + '\n', logger->str());
2974+
#else
2975+
ASSERT_EQUALS("", logger->str());
2976+
#endif
2977+
}
2978+
29672979
void ignorepaths1() {
29682980
REDIRECT;
29692981
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)