|
BpsCmdlineParser & | addHelpSwitch (QChar aKey, const QString &aName, const QString &aInfo) |
| Adds a help-type switch with either a single character key and / or a key name. More...
|
|
BpsCmdlineParser & | addMandatory (const QString &aParam) |
| Add a mandatory parameter. More...
|
|
BpsCmdlineParser & | addOption (QChar aKey, const QString &aName, const QString &aParam, const QString &aInfo) |
| Adds a option with either a single character key and / or a key name. More...
|
|
BpsCmdlineParser & | addOptional (const QString &aParam) |
| Add a single optional parameter. More...
|
|
BpsCmdlineParser & | addOptionals (const QString &aParam) |
| Add a multiple optional parameter. More...
|
|
BpsCmdlineParser & | addOptions (QChar aKey, const QString &aName, const QString &aParam, const QString &aInfo) |
| Adds a option that can occure multiple times with either a single character key and / or a key name. More...
|
|
BpsCmdlineParser & | addSwitch (QChar aKey, const QString &aName, const QString &aInfo) |
| Adds a switch with either a single character key and / or a key name. More...
|
|
QString | help (int aWidth=79) const |
| Formats a help message for the command line parser. More...
|
|
QString | mandatory (const QString &aParam) const |
| Query a mandatory parameter after parsing the arguments. More...
|
|
QString | option (QChar aKey, const QString &aName=QString()) const |
| Query an option value after parsing the arguments. More...
|
|
QString | optional (const QString &aParam) const |
| Query an optional single parameter after parsing the arguments. More...
|
|
QStringList | optionals () const |
| Query the multiple optional parameter after parsing the arguments. More...
|
|
QStringList | options (QChar aKey, const QString &aName=QString()) const |
| Query options values after parsing the arguments. More...
|
|
BpsCmdlineParser & | parse () |
| Parses the command line. More...
|
|
QString | program () const |
| Query the invoked program after parsing the arguments. More...
|
|
BpsCmdlineParser & | setDescription (const QString &aDescription) |
| Set the description what the program is supposed to do. More...
|
|
BpsCmdlineParser & | setProgram (const QString &aName) |
| Set the program name used by the help() funcion. More...
|
|
bool | switchState (QChar aKey, const QString &aName=QString()) const |
| Query a switch after parsing the arguments. More...
|
|
|
| BpsCmdlineParser (QObject *aParent=nullptr) |
| Default constructor for the BpsCmdlineParser class. More...
|
|
bool | blockSignals (bool block) |
|
const QObjectList & | children () const const |
|
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
|
void | deleteLater () |
|
void | destroyed (QObject *obj) |
|
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
|
bool | disconnect (const QObject *receiver, const char *method) const const |
|
void | dumpObjectInfo () |
|
void | dumpObjectInfo () const const |
|
void | dumpObjectTree () |
|
void | dumpObjectTree () const const |
|
QList< QByteArray > | dynamicPropertyNames () const const |
|
virtual bool | event (QEvent *e) |
|
virtual bool | eventFilter (QObject *watched, QEvent *event) |
|
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
|
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
|
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
|
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
|
bool | inherits (const char *className) const const |
|
void | installEventFilter (QObject *filterObj) |
|
bool | isWidgetType () const const |
|
bool | isWindowType () const const |
|
void | killTimer (int id) |
|
virtual const QMetaObject * | metaObject () const const |
|
void | moveToThread (QThread *targetThread) |
|
QString | objectName () const const |
|
void | objectNameChanged (const QString &objectName) |
|
QObject * | parent () const const |
|
QVariant | property (const char *name) const const |
|
| Q_CLASSINFO (Name, Value) |
|
| Q_DISABLE_COPY (Class) |
|
| Q_DISABLE_COPY_MOVE (Class) |
|
| Q_DISABLE_MOVE (Class) |
|
| Q_EMIT Q_EMIT |
|
| Q_ENUM (...) |
|
| Q_ENUM_NS (...) |
|
| Q_ENUMS (...) |
|
| Q_FLAG (...) |
|
| Q_FLAG_NS (...) |
|
| Q_FLAGS (...) |
|
| Q_GADGET Q_GADGET |
|
| Q_INTERFACES (...) |
|
| Q_INVOKABLE Q_INVOKABLE |
|
| Q_NAMESPACE Q_NAMESPACE |
|
| Q_NAMESPACE_EXPORT (EXPORT_MACRO) |
|
| Q_OBJECT Q_OBJECT |
|
| Q_PROPERTY (...) |
|
| Q_REVISION Q_REVISION |
|
| Q_SET_OBJECT_NAME (Object) |
|
| Q_SIGNAL Q_SIGNAL |
|
| Q_SIGNALS Q_SIGNALS |
|
| Q_SLOT Q_SLOT |
|
| Q_SLOTS Q_SLOTS |
|
T | qFindChild (const QObject *obj, const QString &name) |
|
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
|
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
|
| QObject (QObject *parent) |
|
T | qobject_cast (const QObject *object) |
|
T | qobject_cast (QObject *object) |
|
| QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT |
|
void | removeEventFilter (QObject *obj) |
|
void | setObjectName (const QString &name) |
|
void | setParent (QObject *parent) |
|
bool | setProperty (const char *name, const QVariant &value) |
|
bool | signalsBlocked () const const |
|
int | startTimer (int interval, Qt::TimerType timerType) |
|
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
|
QThread * | thread () const const |
|
|
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
|
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
|
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
|
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
|
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
|
bool | disconnect (const QMetaObject::Connection &connection) |
|
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
|
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
|
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
|
QString | tr (const char *sourceText, const char *disambiguation, int n) |
|
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
|
typedef | QObjectList |
|
virtual void | childEvent (QChildEvent *event) |
|
virtual void | connectNotify (const QMetaMethod &signal) |
|
virtual void | customEvent (QEvent *event) |
|
virtual void | disconnectNotify (const QMetaMethod &signal) |
|
bool | isSignalConnected (const QMetaMethod &signal) const const |
|
int | receivers (const char *signal) const const |
|
QObject * | sender () const const |
|
int | senderSignalIndex () const const |
|
virtual void | timerEvent (QTimerEvent *event) |
|
| objectName |
|
A parser for command line arguments.
Specify the command line syntax with a minimum of statements in a readable way, check it against the actual command line arguments and find the retrieved values.
A command line that a user might have entered is:
foobar testjob -v --config=my.cnf -wall input.dat
The typical usage has three stages:
- Construct a parser specifying what arguments to parse
- Run the parser
- Query the parsed arguments
For the first step setting up the accepted syntax is done by a set of functions like setDescription() and addSwitch(). The final step of running the parser is simply done by calling parse().
A short example implementing a parser for the sample above:
int main(int argc, char **argv)
{
try {
cp
"This program does not do very much at all. It is simply a "
"sample to show how command line parsing is working. Enter "
"a JOBNAME to identify the job and a FILENAME where the data "
"is stored.\n"
"\n"
"NOTES: \n"
" - If FILENAME has no extension, .dat will be assumed.\n"
" - JOBNAME and FILENAME must not contain any whitespaces."
)
.
addSwitch(
'v',
"verbose",
"Write status information to stdout.")
"Provide configuration file. If none provided, "
"the system configuration file will be used.")
} else {
}
}
<<
"Use 'foobar -h' for help." <<
endl;
}
}
A parser for command line arguments.
Definition: bpscmdlineparser.h:98
QString mandatory(const QString &aParam) const
Query a mandatory parameter after parsing the arguments.
BpsCmdlineParser & parse()
Parses the command line.
BpsCmdlineParser & addOptional(const QString &aParam)
Add a single optional parameter.
BpsCmdlineParser & addHelpSwitch(QChar aKey, const QString &aName, const QString &aInfo)
Adds a help-type switch with either a single character key and / or a key name.
BpsCmdlineParser & setProgram(const QString &aName)
Set the program name used by the help() funcion.
bool switchState(QChar aKey, const QString &aName=QString()) const
Query a switch after parsing the arguments.
BpsCmdlineParser & addSwitch(QChar aKey, const QString &aName, const QString &aInfo)
Adds a switch with either a single character key and / or a key name.
BpsCmdlineParser & addMandatory(const QString &aParam)
Add a mandatory parameter.
BpsCmdlineParser & setDescription(const QString &aDescription)
Set the description what the program is supposed to do.
QString help(int aWidth=79) const
Formats a help message for the command line parser.
BpsCmdlineParser & addOption(QChar aKey, const QString &aName, const QString &aParam, const QString &aInfo)
Adds a option with either a single character key and / or a key name.
BPS error exception class.
Definition: bpsexception.h:31
QString message() const
Get the plain message, without location trace information.
QTextStream & endl(QTextStream &stream)
For a better understanding of the function names we'll better define some terms used in the API and its documentation:
- Mandatory A mandatory parameter is a plain text token like e.g. a file name one typically passes to an editor when invoking it.
- Optional A optional parameter is also a plain text token, however as it is optional no error will happen when parsing and no such argument is present.
- Optionals Optionals is an arbitrary number of parameters. Note that everything not matching any other topic will be added to the Optionals. Only one Optionals can be present.
- Switch A switch is an on/off kind of argument without the need of additional information. Example:
–debug
- Option An option is a normally optional argument with a key-value syntax like
–output=out.txt
or -I/usr/include
- Options Options is an arbitraty number of argument with a key-value syntax like
–expression="e/foo/bar/g"
or -ee/foo/bar/i
QString BpsCmdlineParser::help |
( |
int |
aWidth = 79 | ) |
const |
|
slot |
Formats a help message for the command line parser.
The message format is similar to the man pages on unix based operating systems:
SYNOPSYS
foobar JOBNAME [FILENAME] [OPTION]...
DESCRIPTION
This program does not do very much at all. It is simply a sample to show
how command line parsing is working. Enter a JOBNAME to identify the job
and a FILENAME where the data is stored.
NOTES:
-If FILENAME has no extension, .dat will be assumed.
-JOBNAME and FILENAME must not contain any whitespaces.
OPTIONS
-h
Show help.
-v, --verbose
Write status information to stdout.
--config=CFGFILE
Provide configuration file. If none provided, the system configuration
file will be used.
-w LEVEL
Warning level: 'all', 'min', 'none'
- Parameters
-
aWidth | The maximum width of the message. Default is 79. |
- Returns
- The formatted help message.