Browse files

This commit implements a new command line parser, extensible using a

QVariantMap of responses, rather than pre-defined class attributes.

Usable options are added using a series of overloaded 'add()' methods,
following the format:
    add(<command line option>, <stored name>, <default>,
        <short help>, <long help>)

The command line option can be either a single string, or a QStringList
containing multiple aliases to be used for the option. The stored name
is what will be used to retrieve the value after processing. The add()
methods currently support the following types of defaults:
    bool            int             uint
    long long       double          const char *
    QString         QSize           QDateTime

Other types will have to take the general format:
    add(<command line option>, <stored name>, QVariant::Type,
        QVariant<default>, <short help>, <long help>)

Several custom classes have been made pre-built with the needed
arguments for their respective binary:
    MythBackendCommandLineParser
    MythFrontendCommandLineParser
    MythPreviewGeneratorCommandLineParser
    MythWelcomeCommandLineParser
    MythAVTestCommandLineParser
    MythCommFlagCommandLineParser
    MythJobQueueCommandLineParser
Additional classes are defined in the header, but have not yet been
configured. The above were chosen because those binaries already used
the pre-existing MythCommandLineParser.

Once created, all necessary command line processing is done internal to
the class, with no need for an external loop. Since new options can be
added dynamically, there is no longer a need for external access to this
loop to provide support for options not already included in
MythCommandLineParser. The internal processing loop is called using:
    MythCommandLineParser cmdline;
    if (!cmdline.Parse(argc, argv))
        return GENERIC_EXIT_NOT_OK;

Boolean options do not expect an associated value, and will be set to
true, or if given a default, the opposite of their default, when
received.  QString options can optionally have an associated value, and
if not, will be stored as using their given default value.  All other
option types are required to have a value associated. Values must not
have spaces, and must not start with '-'. A dash will trigger a fault as
an invalid option.

QSize options are required to be in the format of '<X>x<Y>', or will
trigger a fault. QMap options are required to be in the format of
'<key>=<value>', and are allowed to be called multiple times, such as
used with the --override-settings option. Additional values will be
collected as independent arguments, and must come after all defined
options. An argument received before an option will trigger a fault.

Once parsed, --override-settings are available as before through
GetSettingsOverride, and additional arguments are available as a
QStringList through GetArgs. Options are available through the '[]' map
operator, or a series of 'to<Type>()' methods, using the stored name.
The following type conversions are available:
    bool                    toBool()
    int                     toInt()
    uint                    toUInt()
    long long               toLongLong()
    double                  toDouble()
    QSize                   toSize()
    QString                 toString()
    QStringList             toStringList()
    QMap<QString, QString>  toMap()
    QDateTime               toDateTime()

For boolean options, toBool() will return the value if set, or else the
default. For all other types, toBool() will return whether or not that
option was set on the command line. All other to<Type> methods will
return the given value if available, or fall back to the set default.

Two other utility methods are available. PrintVersion() will print the
version information as before. PrintHelp() will generate help information
for all registered options. If '--help' is called without a value,
PrintHelp() will print all available options, along with their short
help string. If the short help string is left blank, the options will be
left hidden, and not displayed by this general printout. If '--help' is
called with a value, then a more in-depth page is printed, with aliases
of that option, type, default value, and the long help. If the long help
is left blank, the short help string is used in its place. For both the
short and long help, newline characters are honored, and the entire
block is indented as needed.
  • Loading branch information...
1 parent ff02e57 commit 8bc8dd541300e2acd04c9050033d98985c033af9 @wagnerrp wagnerrp committed Apr 14, 2011
View
1,608 mythtv/libs/libmyth/mythcommandlineparser.cpp
@@ -4,6 +4,11 @@ using namespace std;
#include <QFile>
#include <QFileInfo>
#include <QSize>
+#include <QVariant>
+#include <QVariantList>
+#include <QVariantMap>
+#include <QString>
+#include <QCoreApplication>
#include "mythcommandlineparser.h"
#include "exitcodes.h"
@@ -12,923 +17,924 @@ using namespace std;
#include "mythverbose.h"
#include "mythversion.h"
-MythCommandLineParser::MythCommandLineParser(uint64_t things_to_parse) :
- parseTypes(things_to_parse),
- display(), geometry(),
- logfile(),
- pidfile(),
- infile(),
- outfile(),
- newverbose(),
- username(),
- printexpire(),
- eventString(),
- previewSize(0,0),
- starttime(),
- chanid(0),
- previewFrameNumber(-2),
- previewSeconds(-2),
- daemonize(false),
- printsched(false),
- testsched(false),
- setverbose(false),
- resched(false),
- nosched(false),
- scanvideos(false),
- noupnp(false),
- nojobqueue(false),
- nohousekeeper(false),
- noexpirer(false),
- clearsettingscache(false),
- wantupnprebuild(false),
-
- wantsToExit(false)
-{
-}
-
-bool MythCommandLineParser::PreParse(
- int argc, const char * const * argv, int &argpos, bool &err)
-{
- err = false;
-
- binname = QFileInfo(argv[0]).baseName();
-
- if (argpos >= argc)
- return false;
-
- if ((parseTypes & kCLPDisplay) &&
- (!strcmp(argv[argpos],"-display") ||
- !strcmp(argv[argpos],"--display")))
- {
- if ((argc - 1) > argpos)
- {
- display = argv[argpos+1];
- if (display.startsWith("-"))
- {
- cerr << "Invalid or missing argument to -display option\n";
- err = true;
- return true;
- }
- else
- ++argpos;
- }
- else
- {
- cerr << "Missing argument to -display option\n";
- err = true;
- return true;
- }
+typedef struct helptmp {
+ QString left;
+ QString right;
+ QStringList arglist;
+ CommandLineArg arg;
+} HelpTmp;
- return true;
- }
- else if ((parseTypes & kCLPGeometry) &&
- (!strcmp(argv[argpos],"-geometry") ||
- !strcmp(argv[argpos],"--geometry")))
- {
- if ((argc - 1) > argpos)
- {
- geometry = argv[argpos+1];
- if (geometry.startsWith("-"))
- {
- cerr << "Invalid or missing argument to -geometry option\n";
- err = true;
- return true;
- }
- else
- ++argpos;
- }
- else
- {
- cerr << "Missing argument to -geometry option\n";
- err = true;
- return true;
- }
+MythCommandLineParser::MythCommandLineParser(QString appname) :
+ m_appname(appname), m_allowExtras(false), m_overridesImported(false)
+{
+ LoadArguments();
+}
- return true;
- }
-#ifdef Q_WS_MACX
- else if (!strncmp(argv[argpos],"-psn_",5))
- {
- cerr << "Ignoring Process Serial Number from command line\n";
- return true;
- }
-#endif
- else if ((parseTypes & kCLPVerbose) &&
- (!strcmp(argv[argpos],"-v") ||
- !strcmp(argv[argpos],"--verbose")))
- {
- if ((argc - 1) > argpos)
- {
- if (parse_verbose_arg(argv[argpos+1]) ==
- GENERIC_EXIT_INVALID_CMDLINE)
- {
- wantsToExit = err = true;
- }
- ++argpos;
- }
- else
- {
- cerr << "Missing argument to -v/--verbose option";
- wantsToExit = err = true;
- }
- return true;
- }
- else if ((parseTypes & kCLPSetVerbose) &&
- !strcmp(argv[argpos],"--setverbose"))
+void MythCommandLineParser::add(QStringList arglist, QString name,
+ QVariant::Type type, QVariant def,
+ QString help, QString longhelp)
+{
+ CommandLineArg arg;
+ arg.name = name;
+ arg.type = type;
+ arg.def = def;
+ arg.help = help;
+ arg.longhelp = longhelp;
+
+ QStringList::const_iterator i;
+ for (i = arglist.begin(); i != arglist.end(); ++i)
{
- setverbose = true;
- if ((argc - 1) > argpos)
+ if (!m_registeredArgs.contains(*i))
{
- newverbose = argv[argpos+1];
- ++argpos;
+// cerr << "Adding " << (*i).toLocal8Bit().constData()
+// << " as taking type '" << QVariant::typeToName(type)
+// << "'" << endl;
+ m_registeredArgs.insert(*i, arg);
}
- else
- {
- cerr << "Missing argument to --setverbose option\n";
- wantsToExit = err = true;
- }
- return true;
}
- else if ((parseTypes & kCLPHelp) &&
- (!strcmp(argv[argpos],"-h") ||
- !strcmp(argv[argpos],"--help") ||
- !strcmp(argv[argpos],"--usage")))
- {
- QString help = GetHelpString(true);
- QByteArray ahelp = help.toLocal8Bit();
- cout << ahelp.constData();
- wantsToExit = true;
- return true;
- }
- else if ((parseTypes & kCLPQueryVersion) &&
- !strcmp(argv[argpos],"--version"))
- {
- cout << "Please attach all output as a file in bug reports." << endl;
- cout << "MythTV Version : " << MYTH_SOURCE_VERSION << endl;
- cout << "MythTV Branch : " << MYTH_SOURCE_PATH << endl;
- cout << "Network Protocol : " << MYTH_PROTO_VERSION << endl;
- cout << "Library API : " << MYTH_BINARY_VERSION << endl;
- cout << "QT Version : " << QT_VERSION_STR << endl;
+
+ if (!m_defaults.contains(arg.name))
+ m_defaults[arg.name] = arg.def;
+}
+
+void MythCommandLineParser::PrintVersion(void)
+{
+ cout << "Please attach all output as a file in bug reports." << endl;
+ cout << "MythTV Version : " << MYTH_SOURCE_VERSION << endl;
+ cout << "MythTV Branch : " << MYTH_SOURCE_PATH << endl;
+ cout << "Network Protocol : " << MYTH_PROTO_VERSION << endl;
+ cout << "Library API : " << MYTH_BINARY_VERSION << endl;
+ cout << "QT Version : " << QT_VERSION_STR << endl;
#ifdef MYTH_BUILD_CONFIG
- cout << "Options compiled in:" <<endl;
- cout << MYTH_BUILD_CONFIG << endl;
+ cout << "Options compiled in:" <<endl;
+ cout << MYTH_BUILD_CONFIG << endl;
#endif
- wantsToExit = true;
- return true;
- }
- else if ((parseTypes & kCLPExtra) &&
- argv[argpos][0] != '-')
- // Though it's allowed (err = false), we didn't handle the arg
- return false;
-
- return false;
}
-bool MythCommandLineParser::Parse(
- int argc, const char * const * argv, int &argpos, bool &err)
+void MythCommandLineParser::PrintHelp(void)
{
- err = false;
+ QString help = GetHelpString(true);
+ cerr << help.toLocal8Bit().constData();
+}
- if (argpos >= argc)
- return false;
+QString MythCommandLineParser::GetHelpString(bool with_header) const
+{
+ QString helpstr;
+ QTextStream msg(&helpstr, QIODevice::WriteOnly);
- if ((parseTypes & kCLPWindowed) &&
- (!strcmp(argv[argpos],"-w") ||
- !strcmp(argv[argpos],"--windowed")))
- {
- settingsOverride["RunFrontendInWindow"] = "1";
- return true;
- }
- else if ((parseTypes & kCLPNoWindowed) &&
- (!strcmp(argv[argpos],"-nw") ||
- !strcmp(argv[argpos],"--no-windowed")))
- {
- settingsOverride["RunFrontendInWindow"] = "0";
- return true;
- }
- else if ((parseTypes & kCLPDaemon) &&
- (!strcmp(argv[argpos],"-d") ||
- !strcmp(argv[argpos],"--daemon")))
- {
- daemonize = true;
- return true;
- }
- else if ((parseTypes && kCLPPrintSchedule) &&
- !strcmp(argv[argpos],"--printsched"))
- {
- printsched = true;
- return true;
- }
- else if ((parseTypes && kCLPTestSchedule) &&
- !strcmp(argv[argpos],"--testsched"))
- {
- testsched = true;
- return true;
- }
- else if ((parseTypes && kCLPReschedule) &&
- !strcmp(argv[argpos],"--resched"))
- {
- resched = true;
- return true;
- }
- else if ((parseTypes && kCLPNoSchedule) &&
- !strcmp(argv[argpos],"--nosched"))
- {
- nosched = true;
- return true;
- }
- else if ((parseTypes && kCLPReschedule) &&
- !strcmp(argv[argpos],"--scanvideos"))
- {
- scanvideos = true;
- return true;
- }
- else if ((parseTypes && kCLPNoUPnP) &&
- !strcmp(argv[argpos],"--noupnp"))
- {
- noupnp = true;
- return true;
- }
- else if ((parseTypes && kCLPUPnPRebuild) &&
- !strcmp(argv[argpos],"--upnprebuild"))
- {
- wantupnprebuild = true;
- return true;
- }
- else if ((parseTypes && kCLPNoJobqueue) &&
- !strcmp(argv[argpos],"--nojobqueue"))
- {
- nojobqueue = true;
- return true;
- }
- else if ((parseTypes && kCLPNoHousekeeper) &&
- !strcmp(argv[argpos],"--nohousekeeper"))
- {
- nohousekeeper = true;
- return true;
- }
- else if ((parseTypes && kCLPNoAutoExpire) &&
- !strcmp(argv[argpos],"--noautoexpire"))
- {
- noexpirer = true;
- return true;
- }
- else if ((parseTypes && kCLPClearCache) &&
- !strcmp(argv[argpos],"--clearcache"))
+ if (with_header)
{
- clearsettingscache = true;
- return true;
+ QString versionStr = QString("%1 version: %2 [%3] www.mythtv.org")
+ .arg(m_appname).arg(MYTH_SOURCE_PATH).arg(MYTH_SOURCE_VERSION);
+ msg << versionStr << endl;
}
- else if ((parseTypes & kCLPOverrideSettingsFile) &&
- (!strcmp(argv[argpos],"--override-settings-file")))
+
+ if (toString("showhelp").isEmpty())
{
- if (argc <= argpos)
- {
- cerr << "Missing argument to --override-settings-file option\n";
- err = true;
- return true;
- }
+ // build generic help text
+ if (with_header)
+ msg << "Valid options are: " << endl;
- QString filename = QString::fromLocal8Bit(argv[++argpos]);
- QFile f(filename);
- if (!f.open(QIODevice::ReadOnly))
- {
- QByteArray tmp = filename.toAscii();
- cerr << "Failed to open the override settings file: '"
- << tmp.constData() << "'" << endl;
- err = true;
- return true;
- }
+ QMap<QString, HelpTmp> argmap;
+ QString argname;
+ HelpTmp help;
- char buf[1024];
- int64_t len = f.readLine(buf, sizeof(buf) - 1);
- while (len != -1)
+ QMap<QString, CommandLineArg>::const_iterator i;
+ for (i = m_registeredArgs.begin(); i != m_registeredArgs.end(); ++i)
{
- if (len >= 1 && buf[len-1]=='\n')
- buf[len-1] = 0;
- QString line(buf);
- QStringList tokens = line.split("=", QString::SkipEmptyParts);
- if (tokens.size() == 1)
- tokens.push_back("");
- if (tokens.size() >= 2)
- {
- tokens[0].replace(QRegExp("^[\"']"), "");
- tokens[0].replace(QRegExp("[\"']$"), "");
- tokens[1].replace(QRegExp("^[\"']"), "");
- tokens[1].replace(QRegExp("[\"']$"), "");
- if (!tokens[0].isEmpty())
- settingsOverride[tokens[0]] = tokens[1];
- }
- len = f.readLine(buf, sizeof(buf) - 1);
- }
- return true;
- }
- else if ((parseTypes & kCLPOverrideSettings) &&
- (!strcmp(argv[argpos],"-O") ||
- !strcmp(argv[argpos],"--override-setting")))
- {
- if ((argc - 1) > argpos)
- {
- QString tmpArg = argv[argpos+1];
- if (tmpArg.startsWith("-"))
- {
- cerr << "Invalid or missing argument to "
- << "-O/--override-setting option\n";
- err = true;
- return true;
- }
+ if (i.value().help.isEmpty())
+ // ignore any arguments with no help text
+ continue;
- QStringList pairs = tmpArg.split(",", QString::SkipEmptyParts);
- for (int index = 0; index < pairs.size(); ++index)
+ argname = i.value().name;
+ if (argmap.contains(argname))
+ argmap[argname].arglist << i.key();
+ else
{
- QStringList tokens = pairs[index].split(
- "=", QString::SkipEmptyParts);
- if (tokens.size() == 1)
- tokens.push_back("");
- if (tokens.size() >= 2)
- {
- tokens[0].replace(QRegExp("^[\"']"), "");
- tokens[0].replace(QRegExp("[\"']$"), "");
- tokens[1].replace(QRegExp("^[\"']"), "");
- tokens[1].replace(QRegExp("[\"']$"), "");
- if (!tokens[0].isEmpty())
- settingsOverride[tokens[0]] = tokens[1];
- }
+ help.arglist = QStringList(i.key());
+ help.arg = i.value();
+ argmap[argname] = help;
}
}
- else
+
+ int len, maxlen = 0;
+ QMap<QString, HelpTmp>::iterator i2;
+ for (i2 = argmap.begin(); i2 != argmap.end(); ++i2)
{
- cerr << "Invalid or missing argument to "
- << "-O/--override-setting option\n";
- err = true;
- return true;
+ (*i2).left = (*i2).arglist.join(" OR ");
+ (*i2).right = (*i2).arg.help;
+ len = (*i2).left.length();
+ maxlen = max(len, maxlen);
}
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPGetSettings) && gContext &&
- (!strcmp(argv[argpos],"-G") ||
- !strcmp(argv[argpos],"--get-setting") ||
- !strcmp(argv[argpos],"--get-settings")))
- {
- if ((argc - 1) > argpos)
- {
- QString tmpArg = argv[argpos+1];
- if (tmpArg.startsWith("-"))
- {
- cerr << "Invalid argument to "
- << "-G/--get-setting option\n";
- err = true;
- return true;
- }
+ maxlen += 4;
+ QString pad;
+ pad.fill(' ', maxlen);
+ QStringList rlist;
+ QStringList::const_iterator i3;
- settingsQuery = tmpArg.split(",", QString::SkipEmptyParts);
- }
- else
+ for (i2 = argmap.begin(); i2 != argmap.end(); ++i2)
{
- cerr << "Missing argument to "
- << "-G/--get-setting option\n";
- err = true;
- return true;
- }
+ msg << (*i2).left.leftJustified(maxlen, ' ');
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPLogFile) &&
- (!strcmp(argv[argpos],"-l") ||
- !strcmp(argv[argpos],"--logfile")))
- {
- if ((argc - 1) > argpos)
- {
- logfile = argv[argpos+1];
- if (logfile.startsWith("-"))
- {
- cerr << "Invalid argument to -l/--logfile option\n";
- err = true;
- return true;
- }
- }
- else
- {
- cerr << "Missing argument to -l/--logfile option\n";
- err = true;
- return true;
- }
+ rlist = (*i2).right.split('\n');
+ msg << rlist[0] << endl;
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPPidFile) &&
- (!strcmp(argv[argpos],"-p") ||
- !strcmp(argv[argpos],"--pidfile")))
- {
- if ((argc - 1) > argpos)
- {
- pidfile = argv[argpos+1];
- if (pidfile.startsWith("-"))
- {
- cerr << "Invalid argument to -p/--pidfile option\n";
- err = true;
- return true;
- }
+ for (i3 = rlist.begin() + 1; i3 != rlist.end(); ++i3)
+ msg << pad << *i3 << endl;
}
- else
- {
- cerr << "Missing argument to -p/--pidfile option\n";
- err = true;
- return true;
- }
-
- ++argpos;
- return true;
}
- else if ((parseTypes & kCLPInFile) &&
- !strcmp(argv[argpos],"--infile"))
+ else
{
- if ((argc - 1) > argpos)
- {
- infile = argv[argpos+1];
- if (infile.startsWith("-"))
- {
- cerr << "Invalid argument to --infile option\n";
- err = true;
- return true;
- }
- }
- else
+ // build help for a specific argument
+ QString optstr = "-" + toString("showhelp");
+ if (!m_registeredArgs.contains(optstr))
{
- cerr << "Missing argument to --infile option\n";
- err = true;
- return true;
+ optstr = "-" + optstr;
+ if (!m_registeredArgs.contains(optstr))
+ return QString("Could not find option matching '%s'")
+ .arg(toString("showhelp"));
}
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPOutFile) &&
- !strcmp(argv[argpos],"--outfile"))
- {
- if ((argc - 1) > argpos)
- {
- outfile = argv[argpos+1];
- if (outfile.startsWith("-"))
- {
- cerr << "Invalid argument to --outfile option\n";
- err = true;
- return true;
- }
- }
- else
+ if (with_header)
+ msg << "Option: " << optstr << endl << endl;
+
+ // pull option information, and find aliased options
+ CommandLineArg option = m_registeredArgs[optstr];
+ QMap<QString, CommandLineArg>::const_iterator cmi;
+ QStringList aliases;
+ for (cmi = m_registeredArgs.begin(); cmi != m_registeredArgs.end(); ++cmi)
{
- cerr << "Missing argument to --outfile option\n";
- err = true;
- return true;
+ if (cmi.key() == optstr)
+ continue;
+
+ if (cmi.value().name == option.name)
+ aliases << cmi.key();
}
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPUsername) &&
- !strcmp(argv[argpos],"--user"))
- {
- if ((argc - 1) > argpos)
+ QStringList::const_iterator sli;
+ if (!aliases.isEmpty())
{
- username = argv[argpos+1];
- if (username.startsWith("-"))
- {
- cerr << "Invalid argument to --user option\n";
- err = true;
- return true;
- }
+ sli = aliases.begin();
+ msg << "Aliases: " << *sli << endl;
+ while (++sli != aliases.end())
+ msg << " " << *sli << endl;
}
+
+ msg << "Type: " << QVariant::typeToName(option.type) << endl;
+ if (option.def.canConvert(QVariant::String))
+ msg << "Default: " << option.def.toString() << endl;
+
+ QStringList help;
+ if (!option.longhelp.isEmpty())
+ help = option.longhelp.split("\n");
else
- {
- cerr << "Missing argument to --user option\n";
- err = true;
- return true;
- }
+ help = option.help.split("\n");
- ++argpos;
- return true;
+ sli = help.begin();
+ msg << "Description: " << *sli << endl;
+ while (++sli != help.end())
+ msg << " " << *sli << endl;
}
- else if ((parseTypes & kCLPEvent) &&
- (!strcmp(argv[argpos],"--event")))
+
+ msg.flush();
+ return helpstr;
+}
+
+bool MythCommandLineParser::Parse(int argc, const char * const * argv)
+{
+ bool processed;
+ QString opt, val, name;
+ QVariant::Type type;
+
+ QMap<QString, CommandLineArg>::const_iterator i;
+ for (int argpos = 1; argpos < argc; ++argpos)
{
- if ((argc - 1) > argpos)
+
+ opt = QString::fromLocal8Bit(argv[argpos]);
+// cerr << "Processing: " << argv[argpos] << endl;
+ if (!opt.startsWith("-"))
{
- eventString = argv[argpos+1];
- if (eventString.startsWith("-"))
- {
- cerr << "Invalid argument to --event option\n";
- err = true;
- return true;
- }
+ m_remainingArgs << opt;
+ continue;
}
else
{
- cerr << "Missing argument to --event option\n";
- err = true;
- return true;
- }
-
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPSystemEvent) &&
- (!strcmp(argv[argpos],"--systemevent")))
- {
- if ((argc - 1) > argpos)
- {
- eventString = argv[argpos+1];
- if (eventString.startsWith("-"))
+ if (!m_remainingArgs.empty())
{
- cerr << "Invalid argument to --systemevent option\n";
- err = true;
- return true;
+ cerr << "Command line arguments received out of sequence"
+ << endl;
+ return false;
}
- eventString = QString("SYSTEM_EVENT ") + eventString;
- }
- else
- {
- cerr << "Missing argument to --systemevent option\n";
- err = true;
- return true;
}
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPChannelId) &&
- (!strcmp(argv[argpos],"-c") ||
- !strcmp(argv[argpos],"--chanid")))
- {
- if ((argc - 1) > argpos)
+ processed = false;
+
+ for (i = m_registeredArgs.begin(); i != m_registeredArgs.end(); ++i)
{
- chanid = QString(argv[argpos+1]).toUInt();
- if (!chanid)
+ if (opt == i.key())
{
- cerr << "Invalid argument to -c/--chanid option\n";
- err = true;
- return true;
+ processed = true;
+ name = i.value().name;
+ type = i.value().type;
+
+ if (type == QVariant::Bool)
+ {
+// cerr << " bool set to inverse of default" << endl;
+ // if defined, a bool is set to the opposite of default
+ m_parsed[name] = QVariant(!(i.value().def.toBool()));
+ break;
+ }
+
+ // try to pull value
+ if (++argpos == argc)
+ {
+ // end of list
+ if (type == QVariant::String)
+ {
+// cerr << " string set to default" << endl;
+ // strings can be undefined, and set to
+ // their default value
+ m_parsed[name] = i.value().def;
+ break;
+ }
+
+ // all other types expect a value
+ cerr << "Command line option did not receive value"
+ << endl;
+ return false;
+ }
+
+// cerr << " value found: " << argv[argpos] << endl;
+
+ val = QString::fromLocal8Bit(argv[argpos]);
+ if (val.startsWith("-"))
+ {
+ // new option reached without value
+ if (type == QVariant::String)
+ {
+// cerr << " string set to default" << endl;
+ m_parsed[name] = i.value().def;
+ break;
+ }
+
+ cerr << "Command line option did not receive value"
+ << endl;
+ return false;
+ }
+
+ if (type == QVariant::Int)
+ m_parsed[name] = QVariant(val.toInt());
+ else if (type == QVariant::LongLong)
+ m_parsed[name] = QVariant(val.toLongLong());
+ else if (type == QVariant::StringList)
+ {
+ QStringList slist;
+ if (m_parsed.contains(name))
+ slist = m_parsed[name].toStringList();
+ slist << val;
+ m_parsed[name] = QVariant(slist);
+ }
+ else if (type == QVariant::Map)
+ {
+ // check for missing key/val pair
+ if (!val.contains("="))
+ {
+ cerr << "Command line option did not get expected "
+ "key/value pair" << endl;
+ return false;
+ }
+
+ QStringList slist = val.split("=");
+ QVariantMap vmap;
+ if (m_parsed.contains(name))
+ vmap = m_parsed[name].toMap();
+ vmap[slist[0]] = QVariant(slist[1]);
+ m_parsed[name] = QVariant(vmap);
+ }
+ else if (type == QVariant::Size)
+ {
+ if (!val.contains("x"))
+ {
+ cerr << "Command line option did not get expected " "XxY pair" << endl;
+ return false;
+ }
+ QStringList slist = val.split("x");
+ m_parsed[name] = QSize(slist[0].toInt(), slist[1].toInt());
+ }
+ else
+ m_parsed[name] = QVariant(val);
+ // add more type specifics
+
+ break;
}
}
- else
+#ifdef Q_WS_MACX
+ if (opts.startsWith("-psn_"))
+ cerr << "Ignoring Process Serial Number from command line"
+ << endl;
+ else if (!processed && !m_allowExtras)
+#else
+ if (!processed && !m_allowExtras)
+#endif
{
- cerr << "Missing argument to -c/--chanid option\n";
- err = true;
- return true;
+ cerr << "Unhandled option given on command line" << endl;
+ return false;
}
-
- ++argpos;
- return true;
}
- else if ((parseTypes & kCLPStartTime) &&
- (!strcmp(argv[argpos],"-s") ||
- !strcmp(argv[argpos],"--starttime")))
+
+ return true;
+}
+
+QVariant MythCommandLineParser::operator[](const QString &name)
+{
+ QVariant res("");
+ if (m_parsed.contains(name))
+ res = m_parsed[name];
+ else if (m_defaults.contains(name))
+ res = m_defaults[name];
+ return res;
+}
+
+QMap<QString,QString> MythCommandLineParser::GetSettingsOverride(void)
+{
+ QMap<QString,QString> smap;
+ if (!m_parsed.contains("overridesettings"))
+ return smap;
+
+ QVariantMap vmap = m_parsed["overridesettings"].toMap();
+
+ if (!m_overridesImported)
{
- if ((argc - 1) > argpos)
+ if (m_parsed.contains("overridesettingsfile"))
{
- QString tmp = QString(argv[argpos+1]).trimmed();
- starttime = QDateTime::fromString(tmp, "yyyyMMddhhmmss");
- if (!starttime.isValid() && tmp.length() == 19)
+ QString filename = m_parsed["overridesettingsfile"].toString();
+ if (!filename.isEmpty())
{
- starttime = QDateTime::fromString(tmp, Qt::ISODate);
- }
- if (!starttime.isValid())
- {
- cerr << "Invalid argument to -s/--starttime option\n";
- err = true;
- return true;
+ QFile f(filename);
+ if (f.open(QIODevice::ReadOnly))
+ {
+ char buf[1024];
+ int64_t len = f.readLine(buf, sizeof(buf) - 1);
+ while (len != -1)
+ {
+ if (len >= 1 && buf[len-1]=='\n')
+ buf[len-1] = 0;
+ QString line(buf);
+ QStringList tokens = line.split("=",
+ QString::SkipEmptyParts);
+ if (tokens.size() == 2)
+ {
+ tokens[0].replace(QRegExp("^[\"']"), "");
+ tokens[0].replace(QRegExp("[\"']$"), "");
+ tokens[1].replace(QRegExp("^[\"']"), "");
+ tokens[1].replace(QRegExp("[\"']$"), "");
+ if (!tokens[0].isEmpty())
+ vmap[tokens[0]] = QVariant(tokens[1]);
+ }
+ len = f.readLine(buf, sizeof(buf) - 1);
+ }
+ m_parsed["overridesettings"] = QVariant(vmap);
+ }
+ else
+ {
+ QByteArray tmp = filename.toAscii();
+ cerr << "Failed to open the override settings file: '"
+ << tmp.constData() << "'" << endl;
+ }
}
}
+ m_overridesImported = true;
+ }
+
+ QVariantMap::const_iterator i;
+ for (i = vmap.begin(); i != vmap.end(); ++i)
+ smap[i.key()] = i.value().toString();
+
+ // add windowed boolean
+
+ return smap;
+}
+
+bool MythCommandLineParser::toBool(QString key) const
+{
+ // If value is of type boolean, return its value
+ // If value is of other type, return whether
+ // it was defined, of if it will return
+ // its default value
+
+ bool val = false;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].type() == QVariant::Bool)
+ val = m_parsed[key].toBool();
else
- {
- cerr << "Missing argument to -s/--starttime option\n";
- err = true;
- return true;
- }
+ val = true;
+ return val;
+}
- ++argpos;
- return true;
- }
- else if ((parseTypes & kCLPPrintExpire) &&
- (!strcmp(argv[argpos],"--printexpire")))
- {
- printexpire = "ALL";
- if (((argc - 1) > argpos) &&
- QString(argv[argpos+1]).startsWith("-"))
- {
- printexpire = argv[argpos+1];
- ++argpos;
- }
- return true;
- }
- else if (parseTypes & kCLPGeneratePreview &&
- (!strcmp(argv[argpos],"--seconds")))
+int MythCommandLineParser::toInt(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return 0
+ int val = 0;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::Int))
+ val = m_parsed[key].toInt();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::Int))
+ val = m_defaults[key].toInt();
+ return val;
+}
+
+uint MythCommandLineParser::toUInt(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return 0
+ uint val = 0;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::UInt))
+ val = m_parsed[key].toUInt();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::UInt))
+ val = m_defaults[key].toUInt();
+ return val;
+}
+
+
+long long MythCommandLineParser::toLongLong(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return 0
+ long long val = 0;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::LongLong))
+ val = m_parsed[key].toLongLong();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::LongLong))
+ val = m_defaults[key].toLongLong();
+ return val;
+}
+
+double MythCommandLineParser::toDouble(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return 0.0
+ double val = 0.0;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::Double))
+ val = m_parsed[key].toDouble();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::Double))
+ val = m_defaults[key].toDouble();
+ return val;
+}
+
+QSize MythCommandLineParser::toSize(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return (0,0)
+ QSize val(0,0);
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::Size))
+ val = m_parsed[key].toSize();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::Size))
+ val = m_defaults[key].toSize();
+ return val;
+}
+
+QString MythCommandLineParser::toString(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return empty string
+ QString val("");
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::String))
+ val = m_parsed[key].toString();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::String))
+ val = m_defaults[key].toString();
+ return val;
+}
+
+QStringList MythCommandLineParser::toStringList(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return empty stringlist
+ QStringList val;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::StringList))
+ val << m_parsed[key].toStringList();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::StringList))
+ val = m_defaults[key].toStringList();
+ return val;
+}
+
+QMap<QString,QString> MythCommandLineParser::toMap(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return empty stringmap
+ QMap<QString,QString> val;
+ if (m_parsed.contains(key))
{
- QString tmp;
- if ((argc - 1) > argpos)
+ if (m_parsed[key].canConvert(QVariant::Map))
{
- tmp = argv[argpos+1];
- bool ok = true;
- long long seconds = tmp.toInt(&ok);
- if (ok)
- {
- previewSeconds = seconds;
- ++argpos;
- }
- else
- tmp.clear();
+ QMap<QString,QVariant> tmp = m_parsed[key].toMap();
+ QMap<QString,QVariant>::const_iterator i;
+ for (i = tmp.begin(); i != tmp.end(); ++i)
+ val[i.key()] = i.value().toString();
}
-
- return true;
}
- else if (parseTypes & kCLPGeneratePreview &&
- (!strcmp(argv[argpos],"--frame")))
+ else if (m_defaults.contains(key))
{
- QString tmp;
- if ((argc - 1) > argpos)
+ if (m_defaults[key].canConvert(QVariant::Map))
{
- tmp = argv[argpos+1];
- VERBOSE(VB_IMPORTANT, QString("--frame: %1").arg(tmp));
- bool ok = true;
- long long frame = tmp.toInt(&ok);
- if (ok)
- {
- previewFrameNumber = frame;
- ++argpos;
- }
- else
- tmp.clear();
+ QMap<QString,QVariant> tmp = m_defaults[key].toMap();
+ QMap<QString,QVariant>::const_iterator i;
+ for (i = tmp.begin(); i != tmp.end(); ++i)
+ val[i.key()] = i.value().toString();
}
-
- return true;
}
- else if (parseTypes & kCLPGeneratePreview &&
- (!strcmp(argv[argpos],"--size")))
- {
- QString tmp;
- if ((argc - 1) > argpos)
- {
- tmp = argv[argpos+1];
- int xat = tmp.indexOf("x", 0, Qt::CaseInsensitive);
- if (xat > 0)
- {
- QString widthStr = tmp.left(xat);
- QString heightStr;
- heightStr = tmp.mid(xat + 1);
+ return val;
+}
- bool ok1, ok2;
- previewSize = QSize(widthStr.toInt(&ok1), heightStr.toInt(&ok2));
- if (!ok1 || !ok2)
- {
- VERBOSE(VB_IMPORTANT, QString(
- "Error: Failed to parse preview generator "
- "param '%1'").arg(tmp));
- }
- }
- ++argpos;
- }
+QDateTime MythCommandLineParser::toDateTime(QString key) const
+{
+ // Return matching value if defined, else use default
+ // If key is not registered, return empty datetime
+ QDateTime val;
+ if (m_parsed.contains(key))
+ if (m_parsed[key].canConvert(QVariant::DateTime))
+ val = m_parsed[key].toDateTime();
+ else if (m_defaults.contains(key))
+ if (m_defaults[key].canConvert(QVariant::Int))
+ val = m_defaults[key].toDateTime();
+ return val;
+}
- return true;
- }
- else
- {
- return PreParse(argc, argv, argpos, err);
- }
+void MythCommandLineParser::addHelp(void)
+{
+ add(QStringList( QStringList() << "-h" << "--help" ), "showhelp", "",
+ "Display this help printout.",
+ "Displays a list of all commands available for use with\n"
+ "this application. If another option is provided as an\n"
+ "argument, it will provide detailed information on that\n"
+ "option.");
}
-QString MythCommandLineParser::GetHelpString(bool with_header) const
+void MythCommandLineParser::addVersion(void)
{
- QString str;
- QTextStream msg(&str, QIODevice::WriteOnly);
+ add("--version", "showversion", "Display version information.",
+ "Display informtion about build, including:\n"
+ " version, branch, protocol, library API, Qt\n"
+ " and compiled options.");
+}
- if (with_header)
- {
- QString versionStr = QString("%1 version: %2 [%3] www.mythtv.org")
- .arg(binname).arg(MYTH_SOURCE_PATH).arg(MYTH_SOURCE_VERSION);
- msg << versionStr << endl;
- msg << "Valid options are: " << endl;
- }
+void MythCommandLineParser::addWindowed(bool def)
+{
+ if (def)
+ add(QStringList( QStringList() << "-nw" << "--no-windowed" ),
+ "notwindowed", "Prevent application from running in window.", "");
+ else
+ add(QStringList( QStringList() << "-w" << "--windowed" ), "windowed",
+ "Force application to run in a window.", "");
+}
- if (parseTypes & kCLPHelp)
- {
- msg << "-h or --help "
- << "List valid command line parameters" << endl;
- }
+void MythCommandLineParser::addDaemon(void)
+{
+ add(QStringList( QStringList() << "-d" << "--daemon" ), "daemonize",
+ "Fork application into background after startup.",
+ "Fork application into background, detatching from\n"
+ "the local terminal. Often used with:\n"
+ " --logfile --pidfile\n"
+ " --user");
+}
- if (parseTypes & kCLPLogFile)
- {
- msg << "-l or --logfile filename "
- << "Writes STDERR and STDOUT messages to filename" << endl;
- }
+void MythCommandLineParser::addSettingsOverride(void)
+{
+ add(QStringList( QStringList() << "-O" << "--override-setting" ),
+ "overridesettings", QVariant::Map,
+ "Override a single setting defined by a key=value pair.",
+ "Override a single setting from the database using\n"
+ "options defined as one or more key=value pairs\n"
+ "Multiple can be defined by multiple uses of the\n"
+ "-O option.");
+ add("--override-settings-file", "overridesettingsfile", "",
+ "Define a file of key=value pairs to be\n"
+ "loaded for setting overrides.", "");
+}
- if (parseTypes & kCLPPidFile)
- {
- msg << "-p or --pidfile filename "
- << "Write PID of mythbackend to filename" << endl;
- }
+void MythCommandLineParser::addVerbose(void)
+{
+ add(QStringList( QStringList() << "-v" << "--verbose" ), "verbose",
+ "important,general",
+ "Specify log filtering. Use '-v help' for level info.", "");
+ add("-V", "verboseint", 0U, "",
+ "This option is intended for internal use only.\n"
+ "This option takes an unsigned value corresponding\n"
+ "to the bitwise log verbosity operator.");
+}
- if (parseTypes & kCLPDaemon)
- {
- msg << "-d or --daemon "
- << "Runs program as a daemon" << endl;
- }
+void MythCommandLineParser::addRecording(void)
+{
+ add("--chanid", "chanid", 0U,
+ "Specify chanid of recording to operate on.", "");
+ add("--starttime", "starttime", "",
+ "Specify start time of recording to operate on.", "");
+}
- if (parseTypes & kCLPDisplay)
- {
- msg << "-display X-server "
- << "Create GUI on X-server, not localhost" << endl;
- }
+void MythCommandLineParser::addGeometry(void)
+{
+ add(QStringList( QStringList() << "-geometry" << "--geometry" ), "geometry",
+ "", "Specify window size and position (WxH[+X+Y])", "");
+}
- if (parseTypes & kCLPGeometry)
- {
- msg << "-geometry or --geometry WxH "
- << "Override window size settings" << endl;
- msg << "-geometry WxH+X+Y "
- << "Override window size and position" << endl;
- }
+void MythCommandLineParser::addDisplay(void)
+{
+#ifdef USING_X11
+ add("-display", "display", "", "Specify X server to use.", "");
+#endif
+}
- if (parseTypes & kCLPWindowed)
- {
- msg << "-w or --windowed Run in windowed mode" << endl;
- }
+void MythCommandLineParser::addUPnP(void)
+{
+ add("--noupnp", "noupnp", "Disable use of UPnP.", "");
+}
- if (parseTypes & kCLPNoWindowed)
- {
- msg << "-nw or --no-windowed Run in non-windowed mode "
- << endl;
- }
+void MythCommandLineParser::addLogFile(void)
+{
+ add(QStringList( QStringList() << "-l" << "--logfile" ), "logfile", "",
+ "Writes STDERR and STDOUT messages to filename.",
+ "Redirects messages typically sent to STDERR and STDOUT\n"
+ "to this log file. This is typically used in combination\n"
+ "with --daemon, and if used in combination with --pidfile,\n"
+ "this can be used with log rotaters, using the HUP call\n"
+ "to inform MythTV to reload the file.");
+}
- if (parseTypes & kCLPOverrideSettings)
- {
- msg << "-O or --override-setting KEY=VALUE " << endl
- << " "
- << "Force the setting named 'KEY' to value 'VALUE'" << endl
- << " "
- << "This option may be repeated multiple times" << endl;
- }
+void MythCommandLineParser::addPIDFile(void)
+{
+ add(QStringList( QStringList() << "-p" << "--pidfile" ), "pidfile", "",
+ "Write PID of application to filename.",
+ "Write the PID of the currently running process as a single\n"
+ "line to this file. Used for init scripts to know what\n"
+ "process to terminate, and with --logfile and log rotaters\n"
+ "to send a HUP signal to process to have it re-open files.");
+}
- if (parseTypes & kCLPOverrideSettingsFile)
- {
- msg << "--override-settings-file <file> " << endl
- << " "
- << "File containing KEY=VALUE pairs for settings" << endl
- << " Use a comma separated list to return multiple values"
- << endl;
- }
+void MythCommandLineParser::addJob(void)
+{
+ add(QStringList( QStringList() << "-j" << "--jobid" ), "jobid", 0, "",
+ "Intended for internal use only, specify the JobID to match\n"
+ "up with in the database for additional information and the\n"
+ "ability to update runtime status in the database.");
+}
- if (parseTypes & kCLPGetSettings)
- {
- msg << "-G or --get-setting KEY[,KEY2,etc] " << endl
- << " "
- << "Returns the current database setting for 'KEY'" << endl;
- }
+MythBackendCommandLineParser::MythBackendCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHBACKEND)
+{ LoadArguments(); }
- if (parseTypes & kCLPQueryVersion)
- {
- msg << "--version Version information" << endl;
- }
+void MythBackendCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addVersion();
+ addDaemon();
+ addSettingsOverride();
+ addVerbose();
+ addUPnP();
+ addLogFile();
+ addPIDFile();
+
+ add("--printsched", "printsched",
+ "Print upcoming list of scheduled recordings.", "");
+ add("--testsched", "testsched", "do some scheduler testing.", "");
+ add("--resched", "resched",
+ "Trigger a run of the recording scheduler on the existing\n"
+ "master backend.",
+ "This command will connect to the master backend and trigger\n"
+ "a run of the recording scheduler. The call will return\n"
+ "immediately, however the scheduler run may take several\n"
+ "seconds to a minute or longer to complete.");
+ add("--nosched", "nosched", "",
+ "Intended for debugging use only, disable the scheduler\n"
+ "on this backend if it is the master backend, preventing\n"
+ "any recordings from occuring until the backend is\n"
+ "restarted without this option.");
+ add("--scanvideos", "scanvideos",
+ "Trigger a rescan of media content in MythVideo.",
+ "This command will connect to the master backend and trigger\n"
+ "a run of the Video scanner. The call will return\n"
+ "immediately, however the scanner may take several seconds\n"
+ "to tens of minutes, depending on how much new or moved\n"
+ "content it has to hash, and how quickly the scanner can\n"
+ "access those files to do so. If enabled, this will also\n"
+ "trigger the bulk metadata scanner upon completion.");
+ add("--nojobqueue", "nojobqueue", "",
+ "Intended for debugging use only, disable the jobqueue\n"
+ "on this backend. As each jobqueue independently selects\n"
+ "jobs, this will only have any affect on this local\n"
+ "backend.");
+ add("--nohousekeeper", "nohousekeeper", "",
+ "Intended for debugging use only, disable the housekeeper\n"
+ "on this backend if it is the master backend, preventing\n"
+ "any guide processing, recording cleanup, or any other\n"
+ "task performed by the housekeeper.");
+ add("--noautoexpire", "noautoexpire", "",
+ "Intended for debugging use only, disable the autoexpirer\n"
+ "on this backend if it is the master backend, preventing\n"
+ "recordings from being expired to clear room for new\n"
+ "recordings.");
+ add("--event", "event", "", "Send a backend event test message.", "");
+ add("--systemevent", "systemevent", "",
+ "Send a backend SYSTEM_EVENT test message.", "");
+ add("--clearcache", "clearcache",
+ "Trigger a cache clear on all connected MythTV systems.",
+ "This command will connect to the master backend and trigger\n"
+ "a cache clear event, which will subsequently be pushed to\n"
+ "all other connected programs. This event will clear the\n"
+ "local database settings cache used by each program, causing\n"
+ "options to be re-read from the database upon next use.");
+ add("--printexpire", "printexpire", "ALL",
+ "Print upcoming list of recordings to be expired.", "");
+ add("--setverbose", "setverbose", "",
+ "Change debug level of the existing master backend.", "");
+ add("--user", "username", "",
+ "Drop permissions to username after starting.", "");
+}
- if (parseTypes & kCLPVerbose)
- {
- msg << "-v or --verbose debug-level Use '-v help' for level info" << endl;
- }
+MythFrontendCommandLineParser::MythFrontendCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHFRONTEND)
+{ LoadArguments(); }
- if (parseTypes & kCLPSetVerbose)
- {
- msg << "--setverbose debug-level "
- << "Change debug level of running master backend" << endl;
- }
+void MythFrontendCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addVersion();
+ addWindowed(false);
+ addSettingsOverride();
+ addVerbose();
+ addGeometry();
+ addDisplay();
+ addUPnP();
+ addLogFile();
+
+ add(QStringList( QStringList() << "-r" << "--reset" ), "reset",
+ "Resets appearance, settings, and language.", "");
+ add(QStringList( QStringList() << "-p" << "--prompt" ), "prompt",
+ "Always prompt for backend selection.", "");
+ add(QStringList( QStringList() << "-d" << "--disable-autodiscovery" ),
+ "noautodiscovery", "Prevent frontend from using UPnP autodiscovery.", "");
+}
- if (parseTypes & kCLPUsername)
- {
- msg << "--user username "
- << "Drop permissions to username after starting" << endl;
- }
+MythPreviewGeneratorCommandLineParser::MythPreviewGeneratorCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHPREVIEWGEN)
+{ LoadArguments(); }
- if (parseTypes & kCLPPrintExpire)
- {
- msg << "--printexpire "
- << "List of auto-expire programs" << endl;
- }
+void MythPreviewGeneratorCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addVersion();
+ addVerbose();
+ addRecording();
+
+ add("--seconds", "seconds", 0LL, "Number of seconds into video to take preview image.", "");
+ add("--frame", "frame", 0LL, "Number of frames into video to take preview image.", "");
+ add("--size", "size", QSize(0,0), "Dimensions of preview image.", "");
+ add("--infile", "inputfile", "", "Input video for preview generation.", "");
+ add("--outfile" "outputfile", "", "Optional output file for preview generation.", "");
+}
- if (parseTypes & kCLPPrintSchedule)
- {
- msg << "--printsched "
- << "Upcoming scheduled programs" << endl;
- }
+MythWelcomeCommandLineParser::MythWelcomeCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHWELCOME)
+{ LoadArguments(); }
- if (parseTypes & kCLPTestSchedule)
- {
- msg << "--testsched "
- << "Test run scheduler (ignore existing schedule)" << endl;
- }
+void MythWelcomeCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addSettingsOverride();
+ addVersion();
+ addVerbose();
+ addLogFile();
+
+ add(QStringList( QStringList() << "-s" << "--setup" ), "setup",
+ "Run setup for mythshutdown.", "");
+}
- if (parseTypes & kCLPReschedule)
- {
- msg << "--resched "
- << "Force the scheduler to update" << endl;
- }
+MythAVTestCommandLineParser::MythAVTestCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHAVTEST)
+{ LoadArguments(); }
- if (parseTypes & kCLPNoSchedule)
- {
- msg << "--nosched "
- << "Do not perform any scheduling" << endl;
- }
+void MythAVTestCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addSettingsOverride();
+ addVersion();
+ addWindowed(false);
+ addVerbose();
+ addGeometry();
+ addDisplay();
+}
- if (parseTypes & kCLPScanVideos)
- {
- msg << "--scanvideos "
- << "Scan for new video content" << endl;
- }
+MythCommFlagCommandLineParser::MythCommFlagCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHCOMMFLAG)
+{ LoadArguments(); }
- if (parseTypes & kCLPNoUPnP)
- {
- msg << "--noupnp "
- << "Do not enable the UPNP server" << endl;
- }
+void MythCommFlagCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addSettingsOverride();
+ addVersion();
+ addJob();
+
+ add(QStringList( QStringList() << "-f" << "--file" ), "file", "",
+ "Specify file to operate on.");
+ add("--video", "video", "", "Rebuild the seek table for a video (non-recording) file.", "");
+ add("--method", "commmethod", "", "Commercial flagging method[s] to employ:\n"
+ "off, blank, scene, blankscene, logo, all\n"
+ "d2, d2_logo, d2_blank, d2_scene, d2_all\n", "");
+ add("--outputmethod", "outputmethod", "",
+ "Format of output written to outputfile, essentials, full.", "");
+ add("--gencutlist", "gencutlist", "Copy the commercial skip list to the cutlist.", "");
+ add("--clearcutlist", "clearcutlist", "Clear the cutlist.", "");
+ add("--clearskiplist", "clearskiplist", "Clear the commercial skip list.", "");
+ add("--getcutlist", "getcutlist", "Display the current cutlist.", "");
+ add("--getskiplist", "getskiplist", "Display the current commercial skip list.", "");
+ add("--setcutlist", "setcutlist", "", "Set a new cutlist in the form:\n"
+ "#-#[,#-#]... (ie, 1-100,1520-3012,4091-5094)", "");
+ add("--skipdb", "skipdb", "", "Intended for external 3rd party use.");
+ add("--quiet", "quiet", "Don't display commercial flagging progress.", "");
+ add("--very-quiet", "vquiet", "Only display output.", "");
+ add("--queue", "queue", "Insert flagging job into the JobQueue, rather than\n"
+ "running flagging in the foreground.", "");
+ add("--nopercentage", "nopercent", "Don't print percentage done.", "");
+ add("--rebuild", "rebuild", "Do not flag commercials, just rebuild the seektable.", "");
+ add("--force", "force", "Force operation, even if program appears to be in use.", "");
+ add("--dontwritetodb", "dontwritedb", "", "Intended for external 3rd party use.");
+ add("--onlydumpdb", "dumpdb", "", "?");
+ add("--outputfile", "outputfile", "", "File to write commercial flagging output [debug].", "");
+}
- if (parseTypes & kCLPNoJobqueue)
- {
- msg << "--nojobqueue "
- << "Do not start the JobQueue" << endl;
- }
+MythJobQueueCommandLineParser::MythJobQueueCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHJOBQUEUE)
+{ LoadArguments(); }
- if (parseTypes & kCLPNoHousekeeper)
- {
- msg << "--nohousekeeper "
- << "Do not start the Housekeeper" << endl;
- }
+void MythJobQueueCommandLineParser::LoadArguments(void)
+{
+ addHelp();
+ addSettingsOverride();
+ addVersion();
+ addVerbose();
+ addLogFile();
+ addPIDFile();
+ addDaemon();
+}
- if (parseTypes & kCLPNoAutoExpire)
- {
- msg << "--noautoexpire "
- << "Do not start the AutoExpire thread" << endl;
- }
+MythFillDatabaseCommandLineParser::MythFillDatabaseCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHFILLDATABASE)
+{ LoadArguments(); }
- if (parseTypes & kCLPClearCache)
- {
- msg << "--clearcache "
- << "Clear the settings cache on all MythTV servers" << endl;
- }
+void MythFillDatabaseCommandLineParser::LoadArguments(void)
+{
+}
- if (parseTypes & kCLPGeneratePreview)
- {
- msg << "--seconds "
- << "Number of seconds into video that preview should be taken" << endl;
- msg << "--frame "
- << "Number of frames into video that preview should be taken" << endl;
- msg << "--size "
- << "Dimensions of preview image" << endl;
- }
+MythLCDServerCommandLineParser::MythLCDServerCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHLCDSERVER)
+{ LoadArguments(); }
- if (parseTypes & kCLPUPnPRebuild)
- {
- msg << "--upnprebuild "
- << "Force an update of UPNP media" << endl;
- }
+void MythLCDServerCommandLineParser::LoadArguments(void)
+{
+}
- if (parseTypes & kCLPInFile)
- {
- msg << "--infile "
- << "Input file for preview generation" << endl;
- }
+MythMessageCommandLineParser::MythMessageCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHMESSAGE)
+{ LoadArguments(); }
- if (parseTypes & kCLPOutFile)
- {
- msg << "--outfile "
- << "Optional output file for preview generation" << endl;
- }
+void MythMessageCommandLineParser::LoadArguments(void)
+{
+}
- if (parseTypes & kCLPChannelId)
- {
- msg << "--chanid "
- << "Channel ID for preview generation" << endl;
- }
+MythShutdownCommandLineParser::MythShutdownCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHSHUTDOWN)
+{ LoadArguments(); }
- if (parseTypes & kCLPStartTime)
- {
- msg << "--starttime "
- << "Recording start time for preview generation" << endl;
- }
+void MythShutdownCommandLineParser::LoadArguments(void)
+{
+}
- if (parseTypes & kCLPEvent)
- {
- msg << "--event EVENTTEXT "
- << "Send a backend event test message" << endl;
- }
+MythTVSetupCommandLineParser::MythTVSetupCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHTV_SETUP)
+{ LoadArguments(); }
- if (parseTypes & kCLPSystemEvent)
- {
- msg << "--systemevent EVENTTEXT "
- << "Send a backend SYSTEM_EVENT test message" << endl;
- }
+void MythTVSetupCommandLineParser::LoadArguments(void)
+{
+}
- msg.flush();
+MythTranscodeCommandLineParser::MythTranscodeCommandLineParser(void) :
+ MythCommandLineParser(MYTH_APPNAME_MYTHTRANSCODE)
+{ LoadArguments(); }
- return str;
+void MythTranscodeCommandLineParser::LoadArguments(void)
+{
}
View
370 mythtv/libs/libmyth/mythcommandlineparser.h
@@ -4,148 +4,258 @@
#include <QDateTime>
#include <QSize>
#include <QMap>
+#include <QString>
+#include <QVariant>
#include <stdint.h> // for uint64_t
#include "mythexp.h"
-typedef enum {
- kCLPOverrideSettingsFile = 0x0000000001ULL,
- kCLPOverrideSettings = 0x0000000002ULL,
- kCLPWindowed = 0x0000000004ULL,
- kCLPNoWindowed = 0x0000000008ULL,
- kCLPGetSettings = 0x0000000010ULL,
- kCLPQueryVersion = 0x0000000020ULL,
- kCLPDisplay = 0x0000000040ULL,
- kCLPGeometry = 0x0000000080ULL,
- kCLPVerbose = 0x0000000100ULL,
- kCLPSetVerbose = 0x0000000200ULL,
- kCLPHelp = 0x0000000400ULL,
- kCLPExtra = 0x0000000800ULL,
- kCLPDaemon = 0x0000001000ULL,
- kCLPPrintSchedule = 0x0000002000ULL,
- kCLPTestSchedule = 0x0000004000ULL,
- kCLPReschedule = 0x0000008000ULL,
- kCLPNoSchedule = 0x0000010000ULL,
- kCLPNoUPnP = 0x0000020000ULL,
- kCLPUPnPRebuild = 0x0000040000ULL,
- kCLPNoJobqueue = 0x0000080000ULL,
- kCLPNoHousekeeper = 0x0000100000ULL,
- kCLPNoAutoExpire = 0x0000200000ULL,
- kCLPClearCache = 0x0000400000ULL,
- kCLPLogFile = 0x0000800000ULL,
- kCLPPidFile = 0x0001000000ULL,
- kCLPInFile = 0x0002000000ULL,
- kCLPOutFile = 0x0004000000ULL,
- kCLPUsername = 0x0008000000ULL,
- kCLPEvent = 0x0010000000ULL,
- kCLPSystemEvent = 0x0020000000ULL,
- kCLPChannelId = 0x0040000000ULL,
- kCLPStartTime = 0x0080000000ULL,
- kCLPPrintExpire = 0x0100000000ULL,
- kCLPGeneratePreview = 0x0200000000ULL,
- kCLPScanVideos = 0x0400000000ULL,
-} ParseType;
+typedef struct commandlinearg {
+ QString name;
+ QVariant::Type type;
+ QVariant def;
+ QString help;
+ QString longhelp;
+} CommandLineArg;
class MPUBLIC MythCommandLineParser
{
public:
- MythCommandLineParser(uint64_t things_to_parse);
+ MythCommandLineParser(QString);
- bool PreParse(int argc, const char * const * argv, int &argpos, bool &err);
- bool Parse(int argc, const char * const * argv, int &argpos, bool &err);
+ virtual void LoadArguments(void) {};
+ void PrintVersion(void);
+ void PrintHelp(void);
QString GetHelpString(bool with_header) const;
- QMap<QString,QString> GetSettingsOverride(void) const
- { return settingsOverride; }
- QStringList GetSettingsQuery(void) const
- { return settingsQuery; }
- QString GetDisplay(void) const { return display; }
- QString GetGeometry(void) const { return geometry; }
- QString GetLogFilename(void) const { return logfile; }
- QString GetPIDFilename(void) const { return pidfile; }
- QString GetInputFilename(void) const { return infile; }
- QString GetOutputFilename(void) const { return outfile; }
- QString GetNewVerbose(void) const { return newverbose; }
- QString GetUsername(void) const { return username; }
- QString GetPrintExpire(void) const { return printexpire; }
- QString GetEventString(void) const { return eventString; }
-
- QSize GetPreviewSize(void) const { return previewSize; }
- QDateTime GetStartTime(void) const { return starttime; }
- uint GetChanID(void) const { return chanid; }
- long long GetPreviewFrameNumber(void) const { return previewFrameNumber; }
- long long GetPreviewSeconds(void) const { return previewSeconds; }
-
- bool IsDaemonizeEnabled(void) const { return daemonize; }
- bool IsPrintScheduleEnabled(void) const { return printsched; }
- bool IsTestSchedulerEnabled(void) const { return testsched; }
- bool IsSchedulerEnabled(void) const { return !nosched; }
- bool IsUPnPEnabled(void) const { return !noupnp; }
- bool IsJobQueueEnabled(void) const { return !nojobqueue; }
- bool IsHouseKeeperEnabled(void) const { return !nohousekeeper; }
- bool IsAutoExpirerEnabled(void) const { return !noexpirer; }
-
- bool SetVerbose(void) const { return setverbose; }
- bool Reschedule(void) const { return resched; }
- bool ScanVideos(void) const { return scanvideos; }
- bool ClearSettingsCache(void) const { return clearsettingscache; }
- bool WantUPnPRebuild(void) const { return wantupnprebuild; }
-
- bool HasInvalidPreviewGenerationParams(void) const
- {
- return ((!chanid || !starttime.isValid()) && infile.isEmpty());
- }
-
- bool HasBackendCommand(void) const
- {
- return
- !eventString.isEmpty() || wantupnprebuild ||
- setverbose || clearsettingscache ||
- printsched || testsched ||
- resched || scanvideos ||
- !printexpire.isEmpty();
- }
-
- bool WantsToExit(void) const { return wantsToExit; }
+ virtual bool Parse(int argc, const char * const * argv);
+
+// overloaded add constructors for single string options
+ void add(QString arg, QString name, QString help, QString longhelp) // bool
+ { add(arg, name, false, help, longhelp); }
+ void add(QString arg, QString name, bool def, // bool with default
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::Bool,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, int def, // int
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::Int,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, uint def, // uint
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::UInt,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, long long def, // long long
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::LongLong,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, double def, // double
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::Double,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, const char *def, // const char *
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::String,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, QString def, // QString
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::String,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, QSize def, // QSize
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::Size,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, QDateTime def, // QDateTime
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, QVariant::DateTime,
+ QVariant(def), help, longhelp); }
+ void add(QString arg, QString name, QVariant::Type type, // anything else
+ QString help, QString longhelp)
+ { add(QStringList(arg), name, type,
+ QVariant(type), help, longhelp); }
+ void add(QString arg, QString name, QVariant::Type type, // anything else with default
+ QVariant def, QString help, QString longhelp)
+ { add(QStringList(arg), name, type,
+ def, help, longhelp); }
+
+// overloaded add constructors for multi-string options
+ void add(QStringList arglist, QString name, // bool
+ QString help, QString longhelp)
+ { add(arglist, name, false, help, longhelp); }
+ void add(QStringList arglist, QString name, bool def, // bool with default
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::Bool,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, int def, // int
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::Int,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, uint def, // uint
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::UInt,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, long long def, // long long
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::LongLong,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, double def, // float
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::Double,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, const char *def, // const char *
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::String,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, QString def, // QString
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::String,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, QSize def, // QSize
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::Size,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, QDateTime def, // QDateTime
+ QString help, QString longhelp)
+ { add(arglist, name, QVariant::DateTime,
+ QVariant(def), help, longhelp); }
+ void add(QStringList arglist, QString name, QVariant::Type type, // anything else
+ QString help, QString longhelp)
+ { add(arglist, name, type,
+ QVariant(type), help, longhelp); }
+ void add(QStringList arglist, QString name, QVariant::Type type, // anything else with default
+ QVariant def, QString help, QString longhelp);
+
+ QVariant operator[](const QString &name);
+ QStringList GetArgs(void) const { return m_remainingArgs; }
+ QMap<QString,QString> GetSettingsOverride(void);
+
+ bool toBool(QString key) const;
+ int toInt(QString key) const;
+ uint toUInt(QString key) const;
+ long long toLongLong(QString key) const;
+ double toDouble(QString key) const;
+ QSize toSize(QString key) const;
+ QString toString(QString key) const;
+ QStringList toStringList(QString key) const;
+ QMap<QString,QString> toMap(QString key) const;
+ QDateTime toDateTime(QString key) const;
+
+ protected:
+ void allowExtras(bool allow=true) { m_allowExtras = allow; }
+
+ void addHelp(void);
+ void addVersion(void);
+ void addWindowed(bool);
+ void addDaemon(void);
+ void addSettingsOverride(void);
+ void addVerbose(void);
+ void addRecording(void);
+ void addGeometry(void);
+ void addDisplay(void);
+ void addUPnP(void);
+ void addLogFile(void);
+ void addPIDFile(void);
+ void addJob(void);
+
+ QString m_appname;
private:
- uint64_t parseTypes;
-
- QMap<QString,QString> settingsOverride;
- QStringList settingsQuery;
-
- QString binname;
- QString display;
- QString geometry;
- QString logfile;
- QString pidfile;
- QString infile;
- QString outfile;
- QString newverbose;
- QString username;
- QString printexpire;
- QString eventString;
-
- QSize previewSize;
- QDateTime starttime;
-
- uint chanid;
- long long previewFrameNumber;
- long long previewSeconds;
-
- bool daemonize;
- bool printsched;
- bool testsched;
- bool setverbose;
- bool resched;
- bool nosched;
- bool scanvideos;
- bool noupnp;
- bool nojobqueue;
- bool nohousekeeper;
- bool noexpirer;
- bool clearsettingscache;
- bool wantupnprebuild;
- bool wantsToExit;
+ QMap<QString,QVariant> m_parsed;
+ QMap<QString,QVariant> m_defaults;
+ QMap<QString,CommandLineArg> m_registeredArgs;
+ bool m_allowExtras;
+ QStringList m_remainingArgs;
+ bool m_overridesImported;
+};
+
+class MPUBLIC MythBackendCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythBackendCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythFrontendCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythFrontendCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythPreviewGeneratorCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythPreviewGeneratorCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythWelcomeCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythWelcomeCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythAVTestCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythAVTestCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythCommFlagCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythCommFlagCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythJobQueueCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythJobQueueCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythFillDatabaseCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythFillDatabaseCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythLCDServerCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythLCDServerCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythMessageCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythMessageCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythShutdownCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythShutdownCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythTVSetupCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythTVSetupCommandLineParser(void);
+ void LoadArguments(void);
+};
+
+class MPUBLIC MythTranscodeCommandLineParser : public MythCommandLineParser
+{
+ public:
+ MythTranscodeCommandLineParser(void);
+ void LoadArguments(void);
};
View
2 mythtv/libs/libmythbase/mythversion.h
@@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
-#define MYTH_BINARY_VERSION "0.25.20110409-1"
+#define MYTH_BINARY_VERSION "0.25.20110413-1"
/** \brief Increment this whenever the MythTV network protocol changes.
*
View
73 mythtv/programs/mythavtest/main.cpp
@@ -27,70 +27,49 @@ using namespace std;
int main(int argc, char *argv[])
{
- bool cmdline_err;
- MythCommandLineParser cmdline(
- kCLPOverrideSettings |
- kCLPWindowed |
- kCLPNoWindowed |
-#ifdef USING_X11
- kCLPDisplay |
-#endif // USING_X11
- kCLPGeometry |
- kCLPVerbose |
- kCLPExtra |
- kCLPHelp);
-
- print_verbose_messages |= VB_PLAYBACK | VB_LIBAV;
-
- for (int argpos = 1; argpos < argc; ++argpos)
+ MythAVTestCommandLineParser cmdline;
+ if (!cmdline.Parse(argc, argv))
{
- if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
- {
- if (cmdline_err)
- return GENERIC_EXIT_INVALID_CMDLINE;
- if (cmdline.WantsToExit())
- return GENERIC_EXIT_OK;
- }
+ cmdline.PrintHelp();
+ return GENERIC_EXIT_INVALID_CMDLINE;
+ }
+
+ if (cmdline.toBool("showhelp"))
+ {
+ cmdline.PrintHelp();
+ return GENERIC_EXIT_OK;
+ }
+
+ if (cmdline.toBool("showversion"))
+ {
+ cmdline.PrintVersion();
+ return GENERIC_EXIT_OK;
}
QApplication a(argc, argv);
QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHAVTEST);
- int argpos = 1;
QString filename = "";
- while (argpos < a.argc())
- {
- if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
- {
- if (cmdline_err)
- return GENERIC_EXIT_INVALID_CMDLINE;
- if (cmdline.WantsToExit())
- return GENERIC_EXIT_OK;
- }
- else if (a.argv()[argpos][0] != '-')
- {
- filename = a.argv()[argpos];
- }
- else
- {
+ if (cmdline.toBool("verbose"))
+ if (parse_verbose_arg(cmdline.toString("verbose")) ==
+ GENERIC_EXIT_INVALID_CMDLINE)
return GENERIC_EXIT_INVALID_CMDLINE;
- }
-
- ++argpos;
- }
- if (!cmdline.GetDisplay().isEmpty())
+ if (!cmdline.toString("display").isEmpty())
{
- MythUIHelper::SetX11Display(cmdline.GetDisplay());
+ MythUIHelper::SetX11Display(cmdline.toString("display"));
}
- if (!cmdline.GetGeometry().isEmpty())
+ if (!cmdline.toString("geometry").isEmpty())
{
- MythUIHelper::ParseGeometryOverride(cmdline.GetGeometry());
+ MythUIHelper::ParseGeometryOverride(cmdline.toString("geometry"));
}
+ if (cmdline.GetArgs().size() >= 1)
+ filename = cmdline.GetArgs()[0];
+
gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init())
{
View
88 mythtv/programs/mythbackend/main.cpp
@@ -58,47 +58,23 @@
int main(int argc, char **argv)
{
- bool cmdline_err;
- MythCommandLineParser cmdline(
- kCLPDaemon |
- kCLPHelp |
- kCLPOverrideSettingsFile |
- kCLPOverrideSettings |
- kCLPQueryVersion |
- kCLPPrintSchedule |
- kCLPTestSchedule |
- kCLPReschedule |
- kCLPNoSchedule |
- kCLPScanVideos |
- kCLPNoUPnP |
- kCLPUPnPRebuild |
- kCLPNoJobqueue |
- kCLPNoHousekeeper |
- kCLPNoAutoExpire |
- kCLPClearCache |
- kCLPVerbose |
- kCLPSetVerbose |
- kCLPLogFile |
- kCLPPidFile |
- kCLPInFile |
- kCLPOutFile |
- kCLPUsername |
- kCLPEvent |
- kCLPSystemEvent |
- kCLPChannelId |
- kCLPStartTime |
- kCLPPrintExpire);
-
- for (int argpos = 0; argpos < argc; ++argpos)
+ MythBackendCommandLineParser cmdline;
+ if (!cmdline.Parse(argc, argv))
{
- if (cmdline.PreParse(argc, argv, argpos, cmdline_err))
- {
- if (cmdline_err)
- return GENERIC_EXIT_INVALID_CMDLINE;
-
- if (cmdline.WantsToExit())
- return GENERIC_EXIT_OK;
- }
+ cmdline.PrintHelp();
+ return GENERIC_EXIT_INVALID_CMDLINE;
+ }
+
+ if (cmdline.toBool("showversion"))
+ {
+ cmdline.PrintVersion();
+ return GENERIC_EXIT_OK;
+ }
+
+ if (cmdline.toBool("showhelp"))
+ {
+ cmdline.PrintHelp();
+ return GENERIC_EXIT_OK;
}
#ifndef _WIN32
@@ -112,27 +88,13 @@ int main(int argc, char **argv)
#endif
QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHBACKEND);
- for (int argpos = 1; argpos < a.argc(); ++argpos)
- {
- if (cmdline.Parse(a.argc(), a.argv(), argpos, cmdline_err))
- {
- if (cmdline_err)
- return GENERIC_EXIT_INVALID_CMDLINE;
-
- if (cmdline.WantsToExit())
- return GENERIC_EXIT_OK;
- }
- else
- {
- cerr << "Invalid argument: " << a.argv()[argpos] << endl;
- QByteArray help = cmdline.GetHelpString(true).toLocal8Bit();
- cout << help.constData();
- return GENERIC_EXIT_INVALID_CMDLINE;
- }
- }
+ logfile = cmdline.toString("logfile");
+ pidfile = cmdline.toString("pidfile");
- logfile = cmdline.GetLogFilename();
- pidfile = cmdline.GetPIDFilename();
+ if (cmdline.toBool("verbose"))
+ if (parse_verbose_arg(cmdline.toString("verbose")) ==
+ GENERIC_EXIT_INVALID_CMDLINE)
+ return GENERIC_EXIT_INVALID_CMDLINE;
///////////////////////////////////////////////////////////////////////
@@ -156,7 +118,11 @@ int main(int argc, char **argv)
gContext = new MythContext(MYTH_BINARY_VERSION);
- if (cmdline.HasBackendCommand())
+ if (cmdline.toBool("event") || cmdline.toBool("systemevent") ||
+ cmdline.toBool("setverbose") || cmdline.toBool("printsched") ||
+ cmdline.toBool("testsched") || cmdline.toBool("resched") ||
+ cmdline.toBool("scanvideos") || cmdline.toBool("clearcache") ||
+ cmdline.toBool("printexpire"))
{
if (!setup_context(cmdline))
return GENERIC_EXIT_NO_MYTHCONTEXT;