Skip to content

Commit

Permalink
fixed #11919 - Removed deprecated command-line options `--template <t…
Browse files Browse the repository at this point in the history
…emplate>` and `--template-format <template>`
  • Loading branch information
firewave committed Sep 12, 2023
1 parent a87e9e1 commit 6bff609
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 57 deletions.
34 changes: 7 additions & 27 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,20 +898,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}

// Output formatter
else if (std::strcmp(argv[i], "--template") == 0 ||
std::strncmp(argv[i], "--template=", 11) == 0) {
// "--template format"
if (argv[i][10] == '=')
mSettings.templateFormat = argv[i] + 11;
else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead");
++i;
mSettings.templateFormat = argv[i];
} else {
printError("argument to '--template' is missing.");
return false;
}
// TODO: bail out when no placeholders are found?
else if (std::strncmp(argv[i], "--template=", 11) == 0) {
mSettings.templateFormat = argv[i] + 11;
// TODO: bail out when no template is provided?

if (mSettings.templateFormat == "gcc") {
mSettings.templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}";
Expand All @@ -931,21 +920,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mSettings.templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
mSettings.daca = true;
}
// TODO: bail out when no placeholders are found?
}

else if (std::strcmp(argv[i], "--template-location") == 0 ||
std::strncmp(argv[i], "--template-location=", 20) == 0) {
// "--template-location format"
if (argv[i][19] == '=')
mSettings.templateLocation = argv[i] + 20;
else if ((i+1) < argc && argv[i+1][0] != '-') {
printMessage("'--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead");
++i;
mSettings.templateLocation = argv[i];
} else {
printError("argument to '--template-location' is missing.");
return false;
}
else if (std::strncmp(argv[i], "--template-location=", 20) == 0) {
mSettings.templateLocation = argv[i] + 20;
// TODO: bail out when no template is provided?
// TODO: bail out when no placeholders are found?
}

Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Changed interface:

Other:
- Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it.
- The undocumented and deprecated command-line options `--template <template>` and `--template-format <template>` has been removed. Please use `--template=` and `--template-format=` instead.
32 changes: 2 additions & 30 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(templatesSelfcheck);
TEST_CASE(templatesNoPlaceholder);
TEST_CASE(templateFormatInvalid);
TEST_CASE(templateFormatInvalid2);
TEST_CASE(templateFormatEmpty);
TEST_CASE(templateLocationInvalid);
TEST_CASE(templateLocationInvalid2);
TEST_CASE(templateLocationEmpty);
TEST_CASE(xml);
TEST_CASE(xmlver2);
Expand Down Expand Up @@ -1416,24 +1414,12 @@ class TestCmdlineParser : public TestFixture {
}

void templateFormatInvalid() {
REDIRECT;
const char* const argv[] = { "cppcheck", "--template", "--template-location={file}", "file.cpp" };
ASSERT(!parser->parseFromArgs(4, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", GET_REDIRECT_OUTPUT);
}

// TODO: will not error out as he next option does not start with a "-"
void templateFormatInvalid2() {
REDIRECT;
settings->templateFormat.clear();
settings->templateLocation.clear();
const char* const argv[] = { "cppcheck", "--template", "file.cpp" };
ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("file.cpp", settings->templateFormat);
ASSERT_EQUALS("", settings->templateLocation);
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n",
"cppcheck: '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template\".\n", GET_REDIRECT_OUTPUT);
}

// will use the default
Expand All @@ -1453,21 +1439,7 @@ class TestCmdlineParser : public TestFixture {
REDIRECT;
const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" };
ASSERT(!parser->parseFromArgs(4, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT);
}

// TODO: will not error out as the next option does not start with a "-"
void templateLocationInvalid2() {
REDIRECT;
settings->templateFormat.clear();
settings->templateLocation.clear();
const char* const argv[] = { "cppcheck", "--template-location", "file.cpp" };
ASSERT(!parser->parseFromArgs(3, argv));
ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat);
ASSERT_EQUALS("file.cpp", settings->templateLocation);
TODO_ASSERT_EQUALS("",
"cppcheck: '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead\n"
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template-location\".\n", GET_REDIRECT_OUTPUT);
}

// will use the default
Expand Down

0 comments on commit 6bff609

Please sign in to comment.