QCommandLine Class Reference

Main class used to convert parse command line. More...

#include <qcommandline.h>

List of all members.

Public Types

enum  Type { None = 0, Switch, Option, Param }
enum  Flags {
  Default = 0, Mandatory = 0x01, Optional = 0x02, Multiple = 0x04,
  MandatoryMultiple = Mandatory|Multiple, OptionalMultiple = Optional|Multiple
}

Signals

void switchFound (const QString &name)
void optionFound (const QString &name, const QVariant &value)
void paramFound (const QString &name, const QVariant &value)
void parseError (const QString &error)

Public Member Functions

 QCommandLine (QObject *parent=0)
 QCommandLine (const QCoreApplication &app, const QCommandLineConfig &config=QCommandLineConfig(), QObject *parent=0)
 QCommandLine (int argc, char *argv[], const QCommandLineConfig &config=QCommandLineConfig(), QObject *parent=0)
 QCommandLine (const QStringList args, const QCommandLineConfig &config=QCommandLineConfig(), QObject *parent=0)
 ~QCommandLine ()
void setConfig (const QCommandLineConfig &config)
void setConfig (const QCommandLineConfigEntry config[])
QCommandLineConfig config ()
void setArguments (int argc, char *argv[])
void setArguments (QStringList args)
QStringList arguments ()
void enableHelp (bool enable)
bool helpEnabled ()
void enableVersion (bool enable)
bool versionEnabled ()
bool parse ()
void addOption (const QChar &shortName, const QString &longName=QString(), const QString &descr=QString(), QCommandLine::Flags flags=QCommandLine::Optional)
void addSwitch (const QChar &shortName, const QString &longName=QString(), const QString &descr=QString(), QCommandLine::Flags flags=QCommandLine::Optional)
void addParam (const QString &name, const QString &descr=QString(), QCommandLine::Flags flags=QCommandLine::Optional)
void removeOption (const QString &name)
void removeSwitch (const QString &name)
void removeParam (const QString &name)
QString help (bool logo=true)
QString version ()
void showHelp (bool exit=true, int returnCode=0)
void showVersion (bool exit=true, int returnCode=0)

Static Public Attributes

static const
QCommandLineConfigEntry 
helpEntry = { QCommandLine::Switch, QLatin1Char('h'), QLatin1String("help"), tr("Display this help and exit"), QCommandLine::Optional }
static const
QCommandLineConfigEntry 
versionEntry = { QCommandLine::Switch, QLatin1Char('V'), QLatin1String("version"), tr("Display version and exit"), QCommandLine::Optional }


Detailed Description

Main class used to convert parse command line.

Definition at line 39 of file qcommandline.h.


Member Enumeration Documentation

Flags that can be applied to a QCommandLineConfigEntry

Enumerator:
Default  can be used for the last line of a QCommandLineConfigEntry[] .
Mandatory  mandatory argument, will produce a parse error if not present
Optional  optional argument
Multiple  argument can be used multiple time and will produce multiple signals.

Definition at line 56 of file qcommandline.h.

Enum used to determine entry type in QCommandLineConfigEntry

Enumerator:
None  can be used for the last line of a QCommandLineConfigEntry[] .
Switch  a simple switch wihout argument (eg: ls -l)
Option  an option with an argument (eg: tar -f test.tar)
Param  a parameter without '-' delimiter (eg: cp foo bar)

Definition at line 46 of file qcommandline.h.


Constructor & Destructor Documentation

QCommandLine::QCommandLine ( QObject *  parent = 0  ) 

QCommandLine constructor QCoreApplication::instance()->arguments() will be called to get the arguments.

Definition at line 14 of file qcommandline.cpp.

QCommandLine::QCommandLine ( const QCoreApplication &  app,
const QCommandLineConfig &  config = QCommandLineConfig(),
QObject *  parent = 0 
)

QCommandLine constructor

Parameters:
app arguments() will be called on this app to get the list of arguments.
config The parser config
parent The parent for this object
See also:
setConfig

Definition at line 20 of file qcommandline.cpp.

QCommandLine::QCommandLine ( int  argc,
char *  argv[],
const QCommandLineConfig &  config = QCommandLineConfig(),
QObject *  parent = 0 
)

QCommandLine constructor

Parameters:
argc Size of the argv array
argv Argument array
config The parser config
parent The parent for this object
See also:
setArguments

setConfig

Definition at line 31 of file qcommandline.cpp.

QCommandLine::QCommandLine ( const QStringList  args,
const QCommandLineConfig &  config = QCommandLineConfig(),
QObject *  parent = 0 
)

QCommandLine constructor

Parameters:
args Command line arguments
config The parser config
parent The parent for this object
See also:
setArguments

setConfig

Definition at line 42 of file qcommandline.cpp.

QCommandLine::~QCommandLine (  ) 

QCommandLine destructor

Definition at line 53 of file qcommandline.cpp.


Member Function Documentation

void QCommandLine::addOption ( const QChar &  shortName,
const QString &  longName = QString(),
const QString &  descr = QString(),
QCommandLine::Flags  flags = QCommandLine::Optional 
)

Define a new option

Parameters:
shortName Short name for this option (ex: h)
longName Long name for this option (ex: help)
descr Help text
flags Switch flags
See also:
addSwitch

addParam

Definition at line 313 of file qcommandline.cpp.

void QCommandLine::addParam ( const QString &  name,
const QString &  descr = QString(),
QCommandLine::Flags  flags = QCommandLine::Optional 
)

Define a new parameter

Parameters:
name Name, used in help, usage and error messages
descr Help text
flags Parameter flags
See also:
addSwitch

addOption

Definition at line 345 of file qcommandline.cpp.

void QCommandLine::addSwitch ( const QChar &  shortName,
const QString &  longName = QString(),
const QString &  descr = QString(),
QCommandLine::Flags  flags = QCommandLine::Optional 
)

Define a new switch

Parameters:
shortName Short name for this switch (ex: h)
longName Long name for this switch (ex: help)
descr Help text
flags Parameter flags
See also:
addOption

addParam

Definition at line 329 of file qcommandline.cpp.

QStringList QCommandLine::arguments (  ) 

Get command line arguments

Returns:
Command line arguments (like QApplication::arguments())
See also:
arguments

Definition at line 96 of file qcommandline.cpp.

QCommandLineConfig QCommandLine::config (  ) 

Get the current parser configuration

Returns:
The parser configuration
See also:
setConfig

Definition at line 76 of file qcommandline.cpp.

void QCommandLine::enableHelp ( bool  enable  ) 

Enable --help,-h switch

Parameters:
enable true to enable, false to disable
See also:
enableHelp

Definition at line 102 of file qcommandline.cpp.

void QCommandLine::enableVersion ( bool  enable  ) 

Enable --version,-V switch

Parameters:
enable true to enable, false to disable
See also:
versionEnabled

Definition at line 114 of file qcommandline.cpp.

QString QCommandLine::help ( bool  logo = true  ) 

Return the help message

Parameters:
logo also show version message on top of the help message
See also:
version

Definition at line 402 of file qcommandline.cpp.

bool QCommandLine::helpEnabled (  ) 

Check if help is enabled or not.

Returns:
true if help is enabled; otherwise returns false.
See also:
enableVersion

Definition at line 108 of file qcommandline.cpp.

void QCommandLine::optionFound ( const QString &  name,
const QVariant &  value 
) [signal]

Signal emitted when an option is found while parsing

Parameters:
name The "longName" of the switch.
value The value of that option
See also:
parse

addSwitch

void QCommandLine::paramFound ( const QString &  name,
const QVariant &  value 
) [signal]

Signal emitted when a param is found while parsing

Parameters:
name The "longName" of the switch.
value The actual argument
See also:
parse

addSwitch

bool QCommandLine::parse (  ) 

Parse command line and emmit signals when switchs, options, or param are found.

Returns:
true if successfully parsed; otherwise returns false.
See also:
parseError

Definition at line 126 of file qcommandline.cpp.

void QCommandLine::parseError ( const QString &  error  )  [signal]

Signal emitted when a parse error is detected

Parameters:
error Parse error description
See also:
parse

void QCommandLine::removeOption ( const QString &  name  ) 

Remove any option of type QCommandLine::Option with a given shortName or longName.

Parameters:
name the name of the option to remove
See also:
removeParam

removeSwitch

Definition at line 359 of file qcommandline.cpp.

void QCommandLine::removeParam ( const QString &  name  ) 

Remove any option of type QCommandLine::Param with a given shortName or longName.

Parameters:
name the name of the option to remove
See also:
removeOption

removeSwitch

Definition at line 387 of file qcommandline.cpp.

void QCommandLine::removeSwitch ( const QString &  name  ) 

Remove any option of type QCommandLine::Switch with a given shortName or longName.

Parameters:
name the name of the option to remove
See also:
removeOption

removeParam

Definition at line 373 of file qcommandline.cpp.

void QCommandLine::setArguments ( QStringList  args  ) 

Set command line arguments

Parameters:
args A list of arguments
See also:
arguments

Definition at line 90 of file qcommandline.cpp.

void QCommandLine::setArguments ( int  argc,
char *  argv[] 
)

Set command line arguments

Parameters:
argc Size of the argv array
argv Array of arguments
See also:
arguments

Definition at line 82 of file qcommandline.cpp.

void QCommandLine::setConfig ( const QCommandLineConfigEntry  config[]  ) 

Set the parser configuration

Parameters:
config An array containing the configuration
See also:
config

Definition at line 65 of file qcommandline.cpp.

void QCommandLine::setConfig ( const QCommandLineConfig &  config  ) 

Set the parser configuration

Parameters:
config The configuration
See also:
config

Definition at line 59 of file qcommandline.cpp.

void QCommandLine::showHelp ( bool  exit = true,
int  returnCode = 0 
)

Show the help message.

Parameters:
exit Exit if true
returnCode return code of the program if exit is true
See also:
showVersion

Definition at line 486 of file qcommandline.cpp.

void QCommandLine::showVersion ( bool  exit = true,
int  returnCode = 0 
)

Show the version message.

Parameters:
exit Exit if true
returnCode return code of the program if exit is true
See also:
showHelp

Definition at line 496 of file qcommandline.cpp.

void QCommandLine::switchFound ( const QString &  name  )  [signal]

Signal emitted when a switch is found while parsing

Parameters:
name The "longName" of the switch.
See also:
parse

addSwitch

QString QCommandLine::version (  ) 

Return the version message

See also:
help

Definition at line 471 of file qcommandline.cpp.

bool QCommandLine::versionEnabled (  ) 

Check if version is enabled or not.

Returns:
true if version is enabled; otherwise returns false.
See also:
enableHelp

Definition at line 120 of file qcommandline.cpp.


Member Data Documentation

const QCommandLineConfigEntry QCommandLine::helpEntry = { QCommandLine::Switch, QLatin1Char('h'), QLatin1String("help"), tr("Display this help and exit"), QCommandLine::Optional } [static]

Standard --help, -h entry

Definition at line 287 of file qcommandline.h.

const QCommandLineConfigEntry QCommandLine::versionEntry = { QCommandLine::Switch, QLatin1Char('V'), QLatin1String("version"), tr("Display version and exit"), QCommandLine::Optional } [static]

Standard --version, -V entry

Definition at line 292 of file qcommandline.h.


The documentation for this class was generated from the following files:

Generated on Thu Oct 21 15:13:57 2010 for QCommandLine by  doxygen 1.5.8