trikRuntime
trikKernel::CommandLineParser Class Reference

Parser of command-line parameters. More...

#include <commandLineParser.h>

Public Member Functions

void addApplicationDescription (const QString &description)
 Adds application description string. More...
 
void addPositionalArgument (const QString &name, const QString &description)
 Adds new positional argument with its description. More...
 
void addOption (const QString &shortName, const QString &longName, const QString &description)
 Add new option with short and long forms and descriptions. More...
 
void addFlag (const QString &shortName, const QString &longName, const QString &description)
 Add new flag with short and long forms and descriptions. More...
 
bool process (const QCoreApplication &app)
 Parse command line arguments of given application. More...
 
void showHelp () const
 Shows application info and descriptions of all command line arguments. More...
 
QStringList positionalArgs () const
 Returns a list of positional arguments in order in which they appeared in command line. More...
 
bool isSet (const QString &optionShortName) const
 Returns true, if option or flag appeared in command line. More...
 
QString value (const QString &optionShortName) const
 Returns value of an option or an empty string if it is not set. More...
 

Detailed Description

Parser of command-line parameters.

Here "positional argument" is an argument that must be passed to an application in some order, "option" is an argument that must appear in command line in arbitrary order (after last positional argument) and must be preceded by its key (short or long form), and flag is like option, but does not have value and can only be set (when it appears in command line) and unset (when it is omitted). For example, "./trikRun file.js --config ./configs --no-locale" has one positional argument ("file.js"), one option ("--config" with value "./configs") and one flag ("--no-locale). Options and flags in short form are detected by "-" prefix, and in long form --- by "–", so if some positional argument starts with "-" it must be quoted.

Member Function Documentation

void CommandLineParser::addApplicationDescription ( const QString &  description)

Adds application description string.

void CommandLineParser::addFlag ( const QString &  shortName,
const QString &  longName,
const QString &  description 
)

Add new flag with short and long forms and descriptions.

Forms must be passed without "-" prefixes. For example, addFlag("h", "help", tr("Print this help message"));

void CommandLineParser::addOption ( const QString &  shortName,
const QString &  longName,
const QString &  description 
)

Add new option with short and long forms and descriptions.

Forms must be passed without "-" prefixes. For example, addOption("c", "config", tr("Path to a config file"));

void CommandLineParser::addPositionalArgument ( const QString &  name,
const QString &  description 
)

Adds new positional argument with its description.

bool CommandLineParser::isSet ( const QString &  optionShortName) const

Returns true, if option or flag appeared in command line.

QStringList CommandLineParser::positionalArgs ( ) const

Returns a list of positional arguments in order in which they appeared in command line.

bool CommandLineParser::process ( const QCoreApplication &  app)

Parse command line arguments of given application.

Returns
true if parsing is successful. Does not report errors.
void CommandLineParser::showHelp ( ) const

Shows application info and descriptions of all command line arguments.

QString CommandLineParser::value ( const QString &  optionShortName) const

Returns value of an option or an empty string if it is not set.


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