MythCommandLineParser Class Reference

Parent class for defining application command line parsers. More...

#include <mythcommandlineparser.h>

Inheritance diagram for MythCommandLineParser:
MythArchiveHelperCommandLineParser MythAVTestCommandLineParser MythBackendCommandLineParser MythCCExtractorCommandLineParser MythCommFlagCommandLineParser MythFillDatabaseCommandLineParser MythFillNVCommandLineParser MythFrontendCommandLineParser MythJobQueueCommandLineParser MythLCDServerCommandLineParser MythMediaServerCommandLineParser MythMetadataLookupCommandLineParser MythPreviewGeneratorCommandLineParser MythShutdownCommandLineParser MythTranscodeCommandLineParser MythTVSetupCommandLineParser MythUtilCommandLineParser MythWelcomeCommandLineParser

List of all members.

Public Member Functions

 MythCommandLineParser (QString)
 Default constructor for MythCommandLineArg class.
 ~MythCommandLineParser ()
virtual void LoadArguments (void)
void PrintVersion (void) const
 Print application version information.
void PrintHelp (void) const
 Print command line option help.
QString GetHelpString (void) const
 Generate command line option help text.
virtual QString GetHelpHeader (void) const
virtual bool Parse (int argc, const char *const *argv)
 Loop through argv and populate arguments with values.
CommandLineArgadd (QString arg, QString name, bool def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, int def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, uint def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, long long def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, double def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, const char *def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, QString def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, QSize def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, QDateTime def, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, QVariant::Type type, QString help, QString longhelp)
CommandLineArgadd (QString arg, QString name, QVariant::Type type, QVariant def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, bool def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, int def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, uint def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, long long def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, double def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, const char *def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, QString def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, QSize def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, QDateTime def, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, QVariant::Type type, QString help, QString longhelp)
CommandLineArgadd (QStringList arglist, QString name, QVariant::Type type, QVariant def, QString help, QString longhelp)
 Add a new command line argument.
QVariant operator[] (const QString &name)
 Returned stored QVariant for given argument, or default value if not used.
QStringList GetArgs (void) const
 Return list of additional values provided on the command line independent of any keyword.
QMap< QString, QString > GetExtra (void) const
 Return map of additional key/value pairs provided on the command line independent of any registered argument.
QString GetPassthrough (void) const
 Return any text supplied on the command line after a bare '--'.
QMap< QString, QString > GetSettingsOverride (void)
 Return map of key/value pairs provided to override database options.
QString GetLogFilePath (void)
 Helper utility for logging interface to pull path from --logpath.
int GetSyslogFacility (void)
 Helper utility for logging interface to return syslog facility.
LogLevel_t GetLogLevel (void)
 Helper utility for logging interface to filtering level.
bool toBool (QString key) const
 Returns stored QVariant as a boolean.
int toInt (QString key) const
 Returns stored QVariant as an integer, falling to default if not provided.
uint toUInt (QString key) const
 Returns stored QVariant as an unsigned integer, falling to default if not provided.
long long toLongLong (QString key) const
 Returns stored QVariant as a long integer, falling to default if not provided.
double toDouble (QString key) const
 Returns stored QVariant as double floating point value, falling to default if not provided.
QSize toSize (QString key) const
 Returns stored QVariant as a QSize value, falling to default if not provided.
QString toString (QString key) const
 Returns stored QVariant as a QString, falling to default if not provided.
QStringList toStringList (QString key, QString sep="") const
 Returns stored QVariant as a QStringList, falling to default if not provided.
QMap< QString, QString > toMap (QString key) const
 Returns stored QVariant as a QMap, falling to default if not provided.
QDateTime toDateTime (QString key) const
 Returns stored QVariant as a QDateTime, falling to default if not provided.
bool SetValue (const QString &key, QVariant value)
 Set a new stored value for an existing argument definition, or spawn a new definition store value in.
int ConfigureLogging (QString mask="general", unsigned int progress=0)
 Read in logging options and initialize the logging interface.
void ApplySettingsOverride (void)
 Apply all overrides to the global context.
int Daemonize (void)
 Fork application into background, and detatch from terminal.

Protected Member Functions

void allowArgs (bool allow=true)
 Specify that parser should allow and collect values provided independent of any keyword.
void allowExtras (bool allow=true)
 Specify that parser should allow and collect additional key/value pairs not explicitly defined for processing.
void allowPassthrough (bool allow=true)
 Specify that parser should allow a bare '--', and collect all subsequent text as a QString.
void addHelp (void)
 Canned argument definition for --help.
void addVersion (void)
 Canned argument definition for --version.
void addWindowed (void)
 Canned argument definition for --windowed and -no-windowed.
void addMouse (void)
 Canned argument definition for --mouse-cursor and --no-mouse-cursor.
void addDaemon (void)
 Canned argument definition for --daemon.
void addSettingsOverride (void)
 Canned argument definition for --override-setting and --override-settings-file.
void addRecording (void)
 Canned argument definition for --chanid and --starttime.
void addGeometry (void)
 Canned argument definition for --geometry.
void addDisplay (void)
 Canned argument definition for -display.
void addUPnP (void)
 Canned argument definition for --noupnp.
void addLogging (const QString &defaultVerbosity="general", LogLevel_t defaultLogLevel=LOG_INFO)
 Canned argument definition for all logging options, including --verbose, --logpath, --quiet, --loglevel, --syslog and --nodblog.
void addPIDFile (void)
 Canned argument definition for --pidfile.
void addJob (void)
 Canned argument definition for --jobid.
void addInFile (bool addOutFile=false)
 Canned argument definition for --infile and --outfile.

Private Member Functions

int getOpt (int argc, const char *const *argv, int &argpos, QString &opt, QByteArray &val)
 Internal use.
bool ReconcileLinks (void)
 Replace dummy arguments used to define interdependency with pointers to their real counterparts.

Private Attributes

QString m_appname
QMap< QString, CommandLineArg * > m_optionedArgs
QMap< QString, CommandLineArg * > m_namedArgs
bool m_passthroughActive
bool m_overridesImported
bool m_verbose

Detailed Description

Parent class for defining application command line parsers.

This class provides a generic interface for defining and parsing available command line options. Options can be provided manually using the add() method, or one of several canned add*() methods. Once defined, the command line is parsed using the Parse() method, and results are available through Qt standard to<Type>() methods.

Definition at line 112 of file mythcommandlineparser.h.


Constructor & Destructor Documentation

MythCommandLineParser::MythCommandLineParser ( QString  appname  ) 

Default constructor for MythCommandLineArg class.

Definition at line 1121 of file mythcommandlineparser.cpp.

MythCommandLineParser::~MythCommandLineParser (  ) 

Definition at line 1135 of file mythcommandlineparser.cpp.


Member Function Documentation

virtual void MythCommandLineParser::LoadArguments ( void   )  [inline, virtual]
void MythCommandLineParser::PrintVersion ( void   )  const

Print application version information.

Definition at line 1219 of file mythcommandlineparser.cpp.

Referenced by main().

void MythCommandLineParser::PrintHelp ( void   )  const

Print command line option help.

Definition at line 1235 of file mythcommandlineparser.cpp.

Referenced by main().

QString MythCommandLineParser::GetHelpString ( void   )  const

Generate command line option help text.

Generates generic help or specific help, depending on whether a value was provided to the --help option

Definition at line 1246 of file mythcommandlineparser.cpp.

Referenced by PrintHelp().

virtual QString MythCommandLineParser::GetHelpHeader ( void   )  const [inline, virtual]
bool MythCommandLineParser::Parse ( int  argc,
const char *const *  argv 
) [virtual]

Loop through argv and populate arguments with values.

This should not be called until all arguments are added to the parser. This returns false if the parser hits an argument it is not designed to handle.

Definition at line 1395 of file mythcommandlineparser.cpp.

Referenced by main().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
bool  def,
QString  help,
QString  longhelp 
) [inline]
CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
int  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 133 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
uint  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 138 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
long long  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 143 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
double  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 148 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
const char *  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 153 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
QString  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 158 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
QSize  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 163 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
QDateTime  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 168 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
QVariant::Type  type,
QString  help,
QString  longhelp 
) [inline]

Definition at line 173 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QString  arg,
QString  name,
QVariant::Type  type,
QVariant  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 178 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
bool  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 185 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
int  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 190 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
uint  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 195 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
long long  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 200 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
double  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 205 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
const char *  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 210 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
QString  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 215 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
QSize  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 220 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
QDateTime  def,
QString  help,
QString  longhelp 
) [inline]

Definition at line 225 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg* MythCommandLineParser::add ( QStringList  arglist,
QString  name,
QVariant::Type  type,
QString  help,
QString  longhelp 
) [inline]

Definition at line 230 of file mythcommandlineparser.h.

Referenced by add().

CommandLineArg * MythCommandLineParser::add ( QStringList  arglist,
QString  name,
QVariant::Type  type,
QVariant  def,
QString  help,
QString  longhelp 
)

Add a new command line argument.

This is the primary method for adding new arguments for processing. There are several overloaded convenience methods that tie into this, allowing it to be called with fewer inputs.

arglist - list of arguments to allow use of on the command line name - internal name to be used when pulling processed data out type - type of variable to be processed def - default value to provide if one is not supplied or option is not used help - short help text, displayed when printing all available options with '--help' if this is empty, the argument will not be shown longhelp - extended help text, displayed when help about a specific option is requested using '--help <option>'

Allowed types are: Bool - set to value, or default if value is not provided String - set to value, or default if value is not provided Int - set to value, or behaves as counter for multiple uses if value is not provided UInt LongLong Double DateTime - accepts ISO8601 and Myth's flattened version StringList - accepts multiple uses, appended as individual strings Map - accepts multiple pairs, in the syntax "key=value" Size - accepts size in the syntax "XxY"

Definition at line 1185 of file mythcommandlineparser.cpp.

QVariant MythCommandLineParser::operator[] ( const QString &  name  ) 

Returned stored QVariant for given argument, or default value if not used.

Definition at line 1757 of file mythcommandlineparser.cpp.

QStringList MythCommandLineParser::GetArgs ( void   )  const

Return list of additional values provided on the command line independent of any keyword.

Definition at line 1776 of file mythcommandlineparser.cpp.

Referenced by main().

QMap< QString, QString > MythCommandLineParser::GetExtra ( void   )  const

Return map of additional key/value pairs provided on the command line independent of any registered argument.

Definition at line 1784 of file mythcommandlineparser.cpp.

Referenced by SendMessage().

QString MythCommandLineParser::GetPassthrough ( void   )  const

Return any text supplied on the command line after a bare '--'.

Definition at line 1791 of file mythcommandlineparser.cpp.

Referenced by main(), and Parse().

QMap< QString, QString > MythCommandLineParser::GetSettingsOverride ( void   ) 

Return map of key/value pairs provided to override database options.

This method is used for the -O/--override-setting options, as well as the specific arguments to override the window border and mouse cursor. On its first use, this method will also read in any addition settings provided in the --override-settings-file

Definition at line 1803 of file mythcommandlineparser.cpp.

Referenced by ApplySettingsOverride().

QString MythCommandLineParser::GetLogFilePath ( void   ) 

Helper utility for logging interface to pull path from --logpath.

Definition at line 2413 of file mythcommandlineparser.cpp.

Referenced by ConfigureLogging().

int MythCommandLineParser::GetSyslogFacility ( void   ) 

Helper utility for logging interface to return syslog facility.

Definition at line 2447 of file mythcommandlineparser.cpp.

Referenced by ConfigureLogging().

LogLevel_t MythCommandLineParser::GetLogLevel ( void   ) 

Helper utility for logging interface to filtering level.

Definition at line 2458 of file mythcommandlineparser.cpp.

Referenced by ConfigureLogging().

bool MythCommandLineParser::toBool ( QString  key  )  const

Returns stored QVariant as a boolean.

If the stored value is of type boolean, this will return the actual stored or default value. For all other types, this will return whether the argument was supplied on the command line or not.

Definition at line 1888 of file mythcommandlineparser.cpp.

Referenced by ConfigureLogging(), Daemonize(), FlagCommercials(), GetProgramInfo(), GetSettingsOverride(), handle_command(), main(), Parse(), pid_printer(), print_warnings(), QueueCommFlagJob(), run_backend(), and SendMessage().

int MythCommandLineParser::toInt ( QString  key  )  const

Returns stored QVariant as an integer, falling to default if not provided.

Definition at line 1911 of file mythcommandlineparser.cpp.

Referenced by main(), and QueueJob().

uint MythCommandLineParser::toUInt ( QString  key  )  const

Returns stored QVariant as an unsigned integer, falling to default if not provided.

Definition at line 1936 of file mythcommandlineparser.cpp.

Referenced by ConfigureLogging(), GetProgramInfo(), main(), pid_counter(), pid_filter(), and SendMessage().

long long MythCommandLineParser::toLongLong ( QString  key  )  const

Returns stored QVariant as a long integer, falling to default if not provided.

Definition at line 1961 of file mythcommandlineparser.cpp.

Referenced by main().

double MythCommandLineParser::toDouble ( QString  key  )  const

Returns stored QVariant as double floating point value, falling to default if not provided.

Definition at line 1986 of file mythcommandlineparser.cpp.

QSize MythCommandLineParser::toSize ( QString  key  )  const

Returns stored QVariant as a QSize value, falling to default if not provided.

Definition at line 2011 of file mythcommandlineparser.cpp.

Referenced by main().

QString MythCommandLineParser::toString ( QString  key  )  const
QStringList MythCommandLineParser::toStringList ( QString  key,
QString  sep = "" 
) const

Returns stored QVariant as a QStringList, falling to default if not provided.

Optional separator can be specified to split result if stored value is a QString.

Definition at line 2065 of file mythcommandlineparser.cpp.

Referenced by GetArgs(), GetPassthrough(), main(), Parse(), and SendEvent().

QMap< QString, QString > MythCommandLineParser::toMap ( QString  key  )  const

Returns stored QVariant as a QMap, falling to default if not provided.

Definition at line 2095 of file mythcommandlineparser.cpp.

Referenced by GetExtra(), and GetSettingsOverride().

QDateTime MythCommandLineParser::toDateTime ( QString  key  )  const

Returns stored QVariant as a QDateTime, falling to default if not provided.

Definition at line 2128 of file mythcommandlineparser.cpp.

Referenced by GetProgramInfo(), and main().

bool MythCommandLineParser::SetValue ( const QString &  key,
QVariant  value 
)

Set a new stored value for an existing argument definition, or spawn a new definition store value in.

Argument is subsequently marked as being provided on the command line.

Definition at line 2476 of file mythcommandlineparser.cpp.

Referenced by GetLogFilePath(), main(), and Parse().

int MythCommandLineParser::ConfigureLogging ( QString  mask = "general",
unsigned int  progress = 0 
)

Read in logging options and initialize the logging interface.

Definition at line 2499 of file mythcommandlineparser.cpp.

Referenced by main().

void MythCommandLineParser::ApplySettingsOverride ( void   ) 

Apply all overrides to the global context.

WARNING: this must not be called until after MythContext is initialized

Definition at line 2555 of file mythcommandlineparser.cpp.

Referenced by main().

int MythCommandLineParser::Daemonize ( void   ) 

Fork application into background, and detatch from terminal.

Definition at line 2659 of file mythcommandlineparser.cpp.

Referenced by main().

void MythCommandLineParser::allowArgs ( bool  allow = true  )  [protected]

Specify that parser should allow and collect values provided independent of any keyword.

Definition at line 2153 of file mythcommandlineparser.cpp.

Referenced by MythAVTestCommandLineParser::LoadArguments().

void MythCommandLineParser::allowExtras ( bool  allow = true  )  [protected]

Specify that parser should allow and collect additional key/value pairs not explicitly defined for processing.

Definition at line 2171 of file mythcommandlineparser.cpp.

Referenced by MythUtilCommandLineParser::LoadArguments().

void MythCommandLineParser::allowPassthrough ( bool  allow = true  )  [protected]

Specify that parser should allow a bare '--', and collect all subsequent text as a QString.

Definition at line 2190 of file mythcommandlineparser.cpp.

Referenced by MythFillDatabaseCommandLineParser::LoadArguments().

void MythCommandLineParser::addHelp ( void   )  [protected]
void MythCommandLineParser::addVersion ( void   )  [protected]
void MythCommandLineParser::addWindowed ( void   )  [protected]

Canned argument definition for --windowed and -no-windowed.

Definition at line 2230 of file mythcommandlineparser.cpp.

Referenced by MythTVSetupCommandLineParser::LoadArguments(), MythFrontendCommandLineParser::LoadArguments(), and MythAVTestCommandLineParser::LoadArguments().

void MythCommandLineParser::addMouse ( void   )  [protected]

Canned argument definition for --mouse-cursor and --no-mouse-cursor.

Definition at line 2245 of file mythcommandlineparser.cpp.

Referenced by MythTVSetupCommandLineParser::LoadArguments(), and MythFrontendCommandLineParser::LoadArguments().

void MythCommandLineParser::addDaemon ( void   )  [protected]
void MythCommandLineParser::addSettingsOverride ( void   )  [protected]
void MythCommandLineParser::addRecording ( void   )  [protected]
void MythCommandLineParser::addGeometry ( void   )  [protected]
void MythCommandLineParser::addDisplay ( void   )  [protected]

Canned argument definition for -display.

Only works on X11 systems.

Definition at line 2308 of file mythcommandlineparser.cpp.

Referenced by MythTVSetupCommandLineParser::LoadArguments(), MythFrontendCommandLineParser::LoadArguments(), and MythAVTestCommandLineParser::LoadArguments().

void MythCommandLineParser::addUPnP ( void   )  [protected]

Canned argument definition for --noupnp.

Definition at line 2318 of file mythcommandlineparser.cpp.

Referenced by MythFrontendCommandLineParser::LoadArguments(), and MythBackendCommandLineParser::LoadArguments().

void MythCommandLineParser::addLogging ( const QString &  defaultVerbosity = "general",
LogLevel_t  defaultLogLevel = LOG_INFO 
) [protected]
void MythCommandLineParser::addPIDFile ( void   )  [protected]
void MythCommandLineParser::addJob ( void   )  [protected]
void MythCommandLineParser::addInFile ( bool  addOutFile = false  )  [protected]

Canned argument definition for --infile and --outfile.

Definition at line 2404 of file mythcommandlineparser.cpp.

Referenced by MythUtilCommandLineParser::LoadArguments(), and MythAVTestCommandLineParser::LoadArguments().

int MythCommandLineParser::getOpt ( int  argc,
const char *const *  argv,
int &  argpos,
QString &  opt,
QByteArray &  val 
) [private]

Internal use.

Pull next key/value pair from argv.

Definition at line 1311 of file mythcommandlineparser.cpp.

Referenced by Parse().

bool MythCommandLineParser::ReconcileLinks ( void   )  [private]

Replace dummy arguments used to define interdependency with pointers to their real counterparts.

Definition at line 1614 of file mythcommandlineparser.cpp.

Referenced by Parse().


Member Data Documentation

Definition at line 290 of file mythcommandlineparser.h.

Referenced by GetHelpString().

Definition at line 291 of file mythcommandlineparser.h.

Referenced by add(), GetHelpString(), Parse(), and ~MythCommandLineParser().

Definition at line 293 of file mythcommandlineparser.h.

Referenced by getOpt(), and Parse().

Definition at line 294 of file mythcommandlineparser.h.

Referenced by GetSettingsOverride().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Fri May 25 06:42:13 2012 for MythTV by  doxygen 1.6.3