Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 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
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not include the newline because that means you can simply assign this to a variable but you always have to strip the newline which is extremely annoying in a shell environment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me that the newline is added. But maybe the name can be clarified instead.

#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
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
Copy link
Copy Markdown
Collaborator Author

@firewave firewave Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit of a misnomer right now since it is not raw (it has been an awkward name to begin with) as it adds to it.

I have not changed it because it would have ripple effect beyond the actual change.

}
};

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 @@ -444,6 +444,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(checkHeaders);
TEST_CASE(noCheckHeaders);
TEST_CASE(noCheckHeaders2);
TEST_CASE(filesdir);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -3012,6 +3013,17 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(false, settings->checkHeaders);
}

void filesdir() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--filesdir"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Exit, parseFromArgs(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