Skip to content

Commit 98ce46a

Browse files
authored
fixed #11919 - Removed deprecated command-line options --template <template> and --template-format=<template> (#5439)
1 parent a87e9e1 commit 98ce46a

3 files changed

Lines changed: 10 additions & 57 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -898,20 +898,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
898898
}
899899

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

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

936-
else if (std::strcmp(argv[i], "--template-location") == 0 ||
937-
std::strncmp(argv[i], "--template-location=", 20) == 0) {
938-
// "--template-location format"
939-
if (argv[i][19] == '=')
940-
mSettings.templateLocation = argv[i] + 20;
941-
else if ((i+1) < argc && argv[i+1][0] != '-') {
942-
printMessage("'--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead");
943-
++i;
944-
mSettings.templateLocation = argv[i];
945-
} else {
946-
printError("argument to '--template-location' is missing.");
947-
return false;
948-
}
926+
else if (std::strncmp(argv[i], "--template-location=", 20) == 0) {
927+
mSettings.templateLocation = argv[i] + 20;
928+
// TODO: bail out when no template is provided?
949929
// TODO: bail out when no placeholders are found?
950930
}
951931

releasenotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Changed interface:
1414

1515
Other:
1616
- Windows builds now default to the `native` platform instead of `win32A` or `win64`. Please specify it explicitly if you depedent on it.
17+
- The undocumented and deprecated command-line options `--template <template>` and `--template-format <template>` has been removed. Please use `--template=` and `--template-format=` instead.

test/testcmdlineparser.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ class TestCmdlineParser : public TestFixture {
179179
TEST_CASE(templatesSelfcheck);
180180
TEST_CASE(templatesNoPlaceholder);
181181
TEST_CASE(templateFormatInvalid);
182-
TEST_CASE(templateFormatInvalid2);
183182
TEST_CASE(templateFormatEmpty);
184183
TEST_CASE(templateLocationInvalid);
185-
TEST_CASE(templateLocationInvalid2);
186184
TEST_CASE(templateLocationEmpty);
187185
TEST_CASE(xml);
188186
TEST_CASE(xmlver2);
@@ -1416,24 +1414,12 @@ class TestCmdlineParser : public TestFixture {
14161414
}
14171415

14181416
void templateFormatInvalid() {
1419-
REDIRECT;
1420-
const char* const argv[] = { "cppcheck", "--template", "--template-location={file}", "file.cpp" };
1421-
ASSERT(!parser->parseFromArgs(4, argv));
1422-
ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", GET_REDIRECT_OUTPUT);
1423-
}
1424-
1425-
// TODO: will not error out as he next option does not start with a "-"
1426-
void templateFormatInvalid2() {
14271417
REDIRECT;
14281418
settings->templateFormat.clear();
14291419
settings->templateLocation.clear();
14301420
const char* const argv[] = { "cppcheck", "--template", "file.cpp" };
14311421
ASSERT(!parser->parseFromArgs(3, argv));
1432-
ASSERT_EQUALS("file.cpp", settings->templateFormat);
1433-
ASSERT_EQUALS("", settings->templateLocation);
1434-
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n",
1435-
"cppcheck: '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead\n"
1436-
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
1422+
ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template\".\n", GET_REDIRECT_OUTPUT);
14371423
}
14381424

14391425
// will use the default
@@ -1453,21 +1439,7 @@ class TestCmdlineParser : public TestFixture {
14531439
REDIRECT;
14541440
const char* const argv[] = { "cppcheck", "--template-location", "--template={file}", "file.cpp" };
14551441
ASSERT(!parser->parseFromArgs(4, argv));
1456-
ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT);
1457-
}
1458-
1459-
// TODO: will not error out as the next option does not start with a "-"
1460-
void templateLocationInvalid2() {
1461-
REDIRECT;
1462-
settings->templateFormat.clear();
1463-
settings->templateLocation.clear();
1464-
const char* const argv[] = { "cppcheck", "--template-location", "file.cpp" };
1465-
ASSERT(!parser->parseFromArgs(3, argv));
1466-
ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat);
1467-
ASSERT_EQUALS("file.cpp", settings->templateLocation);
1468-
TODO_ASSERT_EQUALS("",
1469-
"cppcheck: '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead\n"
1470-
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
1442+
ASSERT_EQUALS("cppcheck: error: unrecognized command line option: \"--template-location\".\n", GET_REDIRECT_OUTPUT);
14711443
}
14721444

14731445
// will use the default

0 commit comments

Comments
 (0)