Skip to content

Commit c7f88db

Browse files
authored
CmdLineParser: deprecated --template <template> and --template-location <template> (#5331)
Both are bugprone since they just take the next parameter which doesn't start with `-`. Also `--template` has not been documented since 1784239 back in 2011(!). And `--template-location` has never been documented since its induction in f058d9a. That's also why we can have a short deprecation period.
1 parent 33dee83 commit c7f88db

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
899899
}
900900
}
901901

902-
// TODO: deprecate "--template <template>"
903902
// Output formatter
904903
else if (std::strcmp(argv[i], "--template") == 0 ||
905904
std::strncmp(argv[i], "--template=", 11) == 0) {
906905
// "--template format"
907906
if (argv[i][10] == '=')
908907
mSettings.templateFormat = argv[i] + 11;
909908
else if ((i+1) < argc && argv[i+1][0] != '-') {
909+
printMessage("'--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead");
910910
++i;
911911
mSettings.templateFormat = argv[i];
912912
} else {
@@ -935,13 +935,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
935935
}
936936
}
937937

938-
// TODO: deprecate "--template-location <template>"
939938
else if (std::strcmp(argv[i], "--template-location") == 0 ||
940939
std::strncmp(argv[i], "--template-location=", 20) == 0) {
941940
// "--template-location format"
942941
if (argv[i][19] == '=')
943942
mSettings.templateLocation = argv[i] + 20;
944943
else if ((i+1) < argc && argv[i+1][0] != '-') {
944+
printMessage("'--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead");
945945
++i;
946946
mSettings.templateLocation = argv[i];
947947
} else {

releasenotes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
release notes for cppcheck-2.12
1+
Release Notes for Cppcheck 2.12
22

33
New checks:
44
- uselessOverride finds overriding functions that either duplicate code from or delegate back to the base class implementation
@@ -14,6 +14,8 @@ Changed interface:
1414

1515
Deprecations:
1616
- The qmake build system has been deprecated and will be removed in a future version.
17+
- Command-line option '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead.
18+
- Command-line option '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead.
1719

1820
Other:
1921
- "USE_QT6=On" will no longer fallback to Qt5 when Qt6 is not found.

test/testcmdlineparser.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,43 +1335,43 @@ class TestCmdlineParser : public TestFixture {
13351335

13361336
void templates() {
13371337
REDIRECT;
1338-
const char * const argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"};
1338+
const char * const argv[] = {"cppcheck", "--template={file}:{line},{severity},{id},{message}", "--template-location={file}:{line}:{column} {info}", "file.cpp"};
13391339
settings->templateFormat.clear();
13401340
settings->templateLocation.clear();
1341-
ASSERT(parser->parseFromArgs(5, argv));
1341+
ASSERT(parser->parseFromArgs(4, argv));
13421342
ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings->templateFormat);
13431343
ASSERT_EQUALS("{file}:{line}:{column} {info}", settings->templateLocation);
13441344
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
13451345
}
13461346

13471347
void templatesGcc() {
13481348
REDIRECT;
1349-
const char * const argv[] = {"cppcheck", "--template", "gcc", "file.cpp"};
1349+
const char * const argv[] = {"cppcheck", "--template=gcc", "file.cpp"};
13501350
settings->templateFormat.clear();
13511351
settings->templateLocation.clear();
1352-
ASSERT(parser->parseFromArgs(4, argv));
1352+
ASSERT(parser->parseFromArgs(3, argv));
13531353
ASSERT_EQUALS("{file}:{line}:{column}: warning: {message} [{id}]\n{code}", settings->templateFormat);
13541354
ASSERT_EQUALS("{file}:{line}:{column}: note: {info}\n{code}", settings->templateLocation);
13551355
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
13561356
}
13571357

13581358
void templatesVs() {
13591359
REDIRECT;
1360-
const char * const argv[] = {"cppcheck", "--template", "vs", "file.cpp"};
1360+
const char * const argv[] = {"cppcheck", "--template=vs", "file.cpp"};
13611361
settings->templateFormat.clear();
13621362
settings->templateLocation.clear();
1363-
ASSERT(parser->parseFromArgs(4, argv));
1363+
ASSERT(parser->parseFromArgs(3, argv));
13641364
ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings->templateFormat);
13651365
ASSERT_EQUALS("", settings->templateLocation);
13661366
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
13671367
}
13681368

13691369
void templatesEdit() {
13701370
REDIRECT;
1371-
const char * const argv[] = {"cppcheck", "--template", "edit", "file.cpp"};
1371+
const char * const argv[] = {"cppcheck", "--template=edit", "file.cpp"};
13721372
settings->templateFormat.clear();
13731373
settings->templateLocation.clear();
1374-
ASSERT(parser->parseFromArgs(4, argv));
1374+
ASSERT(parser->parseFromArgs(3, argv));
13751375
ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings->templateFormat);
13761376
ASSERT_EQUALS("", settings->templateLocation);
13771377
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
@@ -1439,7 +1439,9 @@ class TestCmdlineParser : public TestFixture {
14391439
ASSERT(!parser->parseFromArgs(3, argv));
14401440
ASSERT_EQUALS("file.cpp", settings->templateFormat);
14411441
ASSERT_EQUALS("", settings->templateLocation);
1442-
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n", "cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
1442+
TODO_ASSERT_EQUALS("cppcheck: error: argument to '--template' is missing.\n",
1443+
"cppcheck: '--template <template>' is deprecated and will be removed in 2.13 - please use '--template=<template>' instead\n"
1444+
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
14431445
}
14441446

14451447
// will use the default
@@ -1462,7 +1464,7 @@ class TestCmdlineParser : public TestFixture {
14621464
ASSERT_EQUALS("cppcheck: error: argument to '--template-location' is missing.\n", GET_REDIRECT_OUTPUT);
14631465
}
14641466

1465-
// TODO: will not error out as he next option does not start with a "-"
1467+
// TODO: will not error out as the next option does not start with a "-"
14661468
void templateLocationInvalid2() {
14671469
REDIRECT;
14681470
settings->templateFormat.clear();
@@ -1471,7 +1473,9 @@ class TestCmdlineParser : public TestFixture {
14711473
ASSERT(!parser->parseFromArgs(3, argv));
14721474
ASSERT_EQUALS("{file}:{line}:{column}: {inconclusive:}{severity}:{inconclusive: inconclusive:} {message} [{id}]\n{code}", settings->templateFormat);
14731475
ASSERT_EQUALS("file.cpp", settings->templateLocation);
1474-
TODO_ASSERT_EQUALS("", "cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
1476+
TODO_ASSERT_EQUALS("",
1477+
"cppcheck: '--template-location <template>' is deprecated and will be removed in 2.13 - please use '--template-location=<template>' instead\n"
1478+
"cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
14751479
}
14761480

14771481
// will use the default

0 commit comments

Comments
 (0)