Skip to content

Commit 07abfa6

Browse files
committed
Add mechanism for marking command line options as removed. ABI bump.
1 parent 2be3dd9 commit 07abfa6

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

mythtv/libs/libmythbase/mythcommandlineparser.cpp

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ const char* NamedOptType(int type)
144144
CommandLineArg::CommandLineArg(QString name, QVariant::Type type,
145145
QVariant def, QString help, QString longhelp) :
146146
ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
147-
m_group(""), m_deprecated(""), m_type(type), m_default(def), m_help(help),
148-
m_longhelp(longhelp)
147+
m_group(""), m_deprecated(""), m_removed(""), m_removedversion(""),
148+
m_type(type), m_default(def), m_help(help), m_longhelp(longhelp)
149149
{
150150
if ((m_type != QVariant::String) && (m_type != QVariant::StringList) &&
151151
(m_type != QVariant::Map))
@@ -160,7 +160,8 @@ CommandLineArg::CommandLineArg(QString name, QVariant::Type type,
160160
*/
161161
CommandLineArg::CommandLineArg(QString name, QVariant::Type type, QVariant def)
162162
: ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
163-
m_group(""), m_deprecated(""), m_type(type), m_default(def)
163+
m_group(""), m_deprecated(""), m_removed(""), m_removedversion(""),
164+
m_type(type), m_default(def)
164165
{
165166
if ((m_type != QVariant::String) && (m_type != QVariant::StringList) &&
166167
(m_type != QVariant::Map))
@@ -176,7 +177,8 @@ CommandLineArg::CommandLineArg(QString name, QVariant::Type type, QVariant def)
176177
*/
177178
CommandLineArg::CommandLineArg(QString name) :
178179
ReferenceCounter(), m_given(false), m_converted(false), m_name(name),
179-
m_deprecated(""), m_type(QVariant::Invalid)
180+
m_deprecated(""), m_removed(""), m_removedversion(""),
181+
m_type(QVariant::Invalid)
180182
{
181183
}
182184

@@ -242,6 +244,10 @@ QString CommandLineArg::GetHelpString(int off, QString group, bool force) const
242244
// option is marked as deprecated, do not show
243245
return helpstr;
244246

247+
if (!m_removed.isEmpty())
248+
// option is marked as removed, do not show
249+
return helpstr;
250+
245251
QString pad;
246252
pad.fill(' ', off);
247253

@@ -284,14 +290,12 @@ QString CommandLineArg::GetLongHelpString(QString keyword) const
284290
if (!m_keywords.contains(keyword))
285291
return helpstr;
286292

293+
// argument has been marked as removed, so warn user of such
294+
if (!m_removed.isEmpty())
295+
PrintRemovedWarning(keyword);
287296
// argument has been marked as deprecated, so warn user of such
288-
if (!m_deprecated.isEmpty())
289-
cerr << QString("****************************************************\n"
290-
" WARNING: %1 has been deprecated\n"
291-
" %2\n"
292-
"****************************************************\n\n")
293-
.arg(keyword).arg(m_deprecated)
294-
.toLocal8Bit().constData();
297+
else if (!m_deprecated.isEmpty())
298+
PrintDeprecatedWarning(keyword);
295299

296300
msg << "Option: " << keyword << endl << endl;
297301

@@ -655,6 +659,17 @@ CommandLineArg* CommandLineArg::SetDeprecated(QString depstr)
655659
return this;
656660
}
657661

662+
/** \brief Set option as removed
663+
*/
664+
CommandLineArg* CommandLineArg::SetRemoved(QString remstr, QString remver)
665+
{
666+
if (remstr.isEmpty())
667+
remstr = "and is no longer available in this version.";
668+
m_removed = remstr;
669+
m_removedversion = remver;
670+
return this;
671+
}
672+
658673
/** \brief Internal use, set argument as parent of given child
659674
*
660675
* This option is intended for internal use only, as part of reconciling
@@ -1063,6 +1078,34 @@ void CommandLineArg::PrintVerbose(void) const
10631078
}
10641079
}
10651080

1081+
/** \brief Internal use. Print warning for removed option.
1082+
*/
1083+
void CommandLineArg::PrintRemovedWarning(QString &keyword) const
1084+
{
1085+
QString warn = QString("%1 has been removed").arg(keyword);
1086+
if (!m_removedversion.isEmpty())
1087+
warn += QString(" as of MythTV %1").arg(m_removedversion);
1088+
1089+
cerr << QString("****************************************************\n"
1090+
" WARNING: %1\n"
1091+
" %2\n"
1092+
"****************************************************\n\n")
1093+
.arg(warn).arg(m_removed)
1094+
.toLocal8Bit().constData();
1095+
}
1096+
1097+
/** \brief Internal use. Print warning for deprecated option.
1098+
*/
1099+
void CommandLineArg::PrintDeprecatedWarning(QString &keyword) const
1100+
{
1101+
cerr << QString("****************************************************\n"
1102+
" WARNING: %1 has been deprecated\n"
1103+
" %2\n"
1104+
"****************************************************\n\n")
1105+
.arg(keyword).arg(m_deprecated)
1106+
.toLocal8Bit().constData();
1107+
}
1108+
10661109
/** \class MythCommandLineParser
10671110
* \brief Parent class for defining application command line parsers
10681111
*
@@ -1457,14 +1500,16 @@ bool MythCommandLineParser::Parse(int argc, const char * const * argv)
14571500
else
14581501
argdef = m_optionedArgs[opt];
14591502

1503+
// argument has been marked as removed, warn user and fail
1504+
if (!argdef->m_removed.isEmpty())
1505+
{
1506+
argdef->PrintRemovedWarning(opt);
1507+
return false;
1508+
}
1509+
14601510
// argument has been marked as deprecated, warn user
14611511
if (!argdef->m_deprecated.isEmpty())
1462-
cerr << QString("****************************************************\n"
1463-
" WARNING: %1 has been deprecated\n"
1464-
" %2\n"
1465-
"****************************************************\n\n")
1466-
.arg(opt).arg(argdef->m_deprecated)
1467-
.toLocal8Bit().constData();
1512+
argdef->PrintDeprecatedWarning(opt);
14681513

14691514
if (m_verbose)
14701515
cerr << "name: " << argdef->GetName().toLocal8Bit().constData()

mythtv/libs/libmythbase/mythcommandlineparser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class MBASE_PUBLIC CommandLineArg : public ReferenceCounter
6060
CommandLineArg* SetBlocks(QStringList opts);
6161

6262
CommandLineArg* SetDeprecated(QString depstr = "");
63+
CommandLineArg* SetRemoved(QString remstr = "", QString remver = "");
6364

6465
static void AllowOneOf(QList<CommandLineArg*> args);
6566

@@ -81,11 +82,16 @@ class MBASE_PUBLIC CommandLineArg : public ReferenceCounter
8182
bool TestLinks(void) const;
8283
void CleanupLinks(void);
8384

85+
void PrintRemovedWarning(QString &keyword) const;
86+
void PrintDeprecatedWarning(QString &keyword) const;
87+
8488
bool m_given;
8589
bool m_converted;
8690
QString m_name;
8791
QString m_group;
8892
QString m_deprecated;
93+
QString m_removed;
94+
QString m_removedversion;
8995
QVariant::Type m_type;
9096
QVariant m_default;
9197
QVariant m_stored;

mythtv/libs/libmythbase/mythversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// Update this whenever the plug-in API changes.
1313
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
1414
/// libmythui class methods used by plug-ins.
15-
#define MYTH_BINARY_VERSION "0.25.20120304-1"
15+
#define MYTH_BINARY_VERSION "0.25.20120307-1"
1616

1717
/** \brief Increment this whenever the MythTV network protocol changes.
1818
*

0 commit comments

Comments
 (0)