|
QCommandLine 0.2.0
|
Main class used to convert parse command line. More...
#include <qcommandline.h>
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 } |
Main class used to convert parse command line.
Definition at line 39 of file qcommandline.h.
| enum QCommandLine::Flags |
Flags that can be applied to a QCommandLineConfigEntry
| 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 QCommandLine::Type |
Enum used to determine entry type in QCommandLineConfigEntry
| 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.
| 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
| app | arguments() will be called on this app to get the list of arguments. |
| config | The parser config |
| parent | The parent for this object |
Definition at line 20 of file qcommandline.cpp.
| QCommandLine::QCommandLine | ( | int | argc, |
| char * | argv[], | ||
| const QCommandLineConfig & | config = QCommandLineConfig(), |
||
| QObject * | parent = 0 |
||
| ) |
QCommandLine constructor
| argc | Size of the argv array |
| argv | Argument array |
| config | The parser config |
| parent | The parent for this object |
Definition at line 31 of file qcommandline.cpp.
| QCommandLine::QCommandLine | ( | const QStringList | args, |
| const QCommandLineConfig & | config = QCommandLineConfig(), |
||
| QObject * | parent = 0 |
||
| ) |
QCommandLine constructor
| args | Command line arguments |
| config | The parser config |
| parent | The parent for this object |
Definition at line 42 of file qcommandline.cpp.
| QCommandLine::~QCommandLine | ( | ) |
QCommandLine destructor
Definition at line 53 of file qcommandline.cpp.
| void QCommandLine::addOption | ( | const QChar & | shortName, |
| const QString & | longName = QString(), |
||
| const QString & | descr = QString(), |
||
| QCommandLine::Flags | flags = QCommandLine::Optional |
||
| ) |
Define a new option
| shortName | Short name for this option (ex: h) |
| longName | Long name for this option (ex: help) |
| descr | Help text |
| flags | Switch flags |
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
| name | Name, used in help, usage and error messages |
| descr | Help text |
| flags | Parameter flags |
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
| shortName | Short name for this switch (ex: h) |
| longName | Long name for this switch (ex: help) |
| descr | Help text |
| flags | Parameter flags |
Definition at line 329 of file qcommandline.cpp.
| QStringList QCommandLine::arguments | ( | ) |
Get command line arguments
Definition at line 96 of file qcommandline.cpp.
| QCommandLineConfig QCommandLine::config | ( | ) |
Get the current parser configuration
Definition at line 76 of file qcommandline.cpp.
| void QCommandLine::enableHelp | ( | bool | enable | ) |
Enable --help,-h switch
| enable | true to enable, false to disable |
Definition at line 102 of file qcommandline.cpp.
| void QCommandLine::enableVersion | ( | bool | enable | ) |
Enable --version,-V switch
| enable | true to enable, false to disable |
Definition at line 114 of file qcommandline.cpp.
| QString QCommandLine::help | ( | bool | logo = true | ) |
Return the help message
| logo | also show version message on top of the help message |
Definition at line 402 of file qcommandline.cpp.
| bool QCommandLine::helpEnabled | ( | ) |
Check if help is enabled or not.
Definition at line 108 of file qcommandline.cpp.
| void QCommandLine::optionFound | ( | const QString & | name, |
| const QVariant & | value | ||
| ) | [signal] |
| void QCommandLine::paramFound | ( | const QString & | name, |
| const QVariant & | value | ||
| ) | [signal] |
| bool QCommandLine::parse | ( | ) |
Parse command line and emmit signals when switchs, options, or param are found.
Definition at line 126 of file qcommandline.cpp.
| void QCommandLine::parseError | ( | const QString & | error | ) | [signal] |
Signal emitted when a parse error is detected
| error | Parse error description |
| void QCommandLine::removeOption | ( | const QString & | name | ) |
Remove any option of type QCommandLine::Option with a given shortName or longName.
| name | the name of the option to remove |
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.
| name | the name of the option to remove |
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.
| name | the name of the option to remove |
Definition at line 373 of file qcommandline.cpp.
| void QCommandLine::setArguments | ( | int | argc, |
| char * | argv[] | ||
| ) |
Set command line arguments
| argc | Size of the argv array |
| argv | Array of arguments |
Definition at line 82 of file qcommandline.cpp.
| void QCommandLine::setArguments | ( | QStringList | args | ) |
Set command line arguments
| args | A list of arguments |
Definition at line 90 of file qcommandline.cpp.
| void QCommandLine::setConfig | ( | const QCommandLineConfigEntry | config[] | ) |
Set the parser configuration
| config | An array containing the configuration |
Definition at line 65 of file qcommandline.cpp.
| void QCommandLine::setConfig | ( | const QCommandLineConfig & | config | ) |
Set the parser configuration
| config | The configuration |
Definition at line 59 of file qcommandline.cpp.
| void QCommandLine::showHelp | ( | bool | exit = true, |
| int | returnCode = 0 |
||
| ) |
Show the help message.
| exit | Exit if true |
| returnCode | return code of the program if exit is true |
Definition at line 486 of file qcommandline.cpp.
| void QCommandLine::showVersion | ( | bool | exit = true, |
| int | returnCode = 0 |
||
| ) |
Show the version message.
| exit | Exit if true |
| returnCode | return code of the program if exit is true |
Definition at line 496 of file qcommandline.cpp.
| void QCommandLine::switchFound | ( | const QString & | name | ) | [signal] |
| QString QCommandLine::version | ( | ) |
| bool QCommandLine::versionEnabled | ( | ) |
Check if version is enabled or not.
Definition at line 120 of file qcommandline.cpp.
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.
1.7.3