Skip to content

CmdLineParser: various refactorings and cleanups as well as testing improvements#5676

Merged
firewave merged 6 commits intocppcheck-opensource:mainfrom
firewave:cmd-xxy
Nov 25, 2023
Merged

CmdLineParser: various refactorings and cleanups as well as testing improvements#5676
firewave merged 6 commits intocppcheck-opensource:mainfrom
firewave:cmd-xxy

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

No description provided.

@firewave
Copy link
Copy Markdown
Collaborator Author

Still requires a couple of more tests and also requires #5672 to be merged first.

Comment thread cli/cmdlineparser.cpp
else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
mPathNames.clear();
mShowHelp = true;
// TODO: make this an exclusive option
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.

"exclusive" option means that it should be processed separately so e.g. --library=missing-lib --help would not bailout with a library error but simply shows the help text. So we could scan for those before before handling all the others.

I tried a few different commands and the behavior is not consistent. Some just do the "left-to-right" until they hit the bail out options and others treat them as truly exclusive. I would like to go with the latter but that will be done in an upcoming PR.

ASSERT_EQUALS("The Product\n", logger->str()); // TODO: include version?
}

// TODO: test extraVersion
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.

That appears to be unused. Does premium make use of that?

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.

No premium does not use extraVersion. I don't remember why we added it maybe it's for "dev" or sha or something..

Comment thread test/testcmdlineparser.cpp Outdated
"}\n");
const char * const argv[] = {"cppcheck", "--version"};
ASSERT(parser->parseFromArgs(2, argv));
ASSERT_EQUALS("The Product\n", logger->str()); // TODO: include version?
Copy link
Copy Markdown
Collaborator Author

@firewave firewave Nov 17, 2023

Choose a reason for hiding this comment

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

The product name should not contain the version number since it is being use as simply the product name is other places. I think we should include the version here.

As different builds might also make use of a different version we should have a way to specify this easily. I do not think the cppcheck.cfg would be the way to specify that.

Comment thread cli/cmdlineparser.cpp Outdated
if (getShowErrorMessages()) {
XMLErrorMessagesLogger xmlLogger;
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName);
ErrorLogger& log = xmlLogger;
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.

I chose this so we keep using the interface. The actual implementation is private and I would like to keep it that way.

Comment thread cli/cmdlineparser.cpp
// print all possible error messages..
else if (std::strcmp(argv[i], "--errorlist") == 0) {
mShowErrorMessages = true;
mSettings.xml = true;
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 was unnecessary and might have interfered with other options since we proceed with "left-to-right" rpocessing.

Comment thread cli/cmdlineparser.cpp
CppCheck::getErrorMessages(xmlLogger);
std::cout << ErrorMessage::getXMLFooter() << std::endl;
}
return true;
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.

We can return here now since we no longer rely on other options. --verbose never had an effect since we print it as XML which always includes the verbose message.


// TODO: test --errorlist with product name

void errorlistverbose1() {
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.

No longer necessary since we no longer rely on --verbose which actually never had any effect at all. Possibly a very old left-over. I did not check the history when this changed.

@firewave firewave force-pushed the cmd-xxy branch 5 times, most recently from 332861d to e567fcf Compare November 20, 2023 19:25
@firewave firewave marked this pull request as ready for review November 20, 2023 19:25
@firewave firewave changed the title CmdLineParser: various refactorings and cleanups CmdLineParser: various refactorings and cleanups as well as testing improvements Nov 20, 2023
"}\n");
const char * const argv[] = {"cppcheck", "--version"};
ASSERT(parser->parseFromArgs(2, argv));
// TODO: somehow the config is not loaded on some systems
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.

I will look into this in the PR which adds proper error reporting to the config loading function.

@firewave firewave merged commit 8e1ae7e into cppcheck-opensource:main Nov 25, 2023
@firewave firewave deleted the cmd-xxy branch November 25, 2023 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants