Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QCommandLineParserPrivate Class Reference
+ Collaboration diagram for QCommandLineParserPrivate:

Classes

struct  PositionalArgumentDefinition
 Documentation for positional arguments. More...
 

Public Member Functions

 QCommandLineParserPrivate ()
 
bool parse (const QStringList &args)
 
void checkParsed (const char *method)
 
QStringList aliases (const QString &name) const
 
QString helpText (bool includeQtOptions) const
 
bool registerFoundOption (const QString &optionName)
 
bool parseOptionValue (const QString &optionName, const QString &argument, QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd)
 Parse the value for a given option, if it was defined to expect one.
 
Q_NORETURN void showHelp (int exitCode, bool includeQtOptions)
 

Public Attributes

QString errorText
 Error text set when parse() returns false.
 
QList< QCommandLineOptioncommandLineOptionList
 The command line options used for parsing.
 
NameHash_t nameHash
 Hash mapping option names to their offsets in commandLineOptionList and optionArgumentList.
 
QHash< qsizetype, QStringListoptionValuesHash
 Option values found (only for options with a value)
 
QStringList optionNames
 Names of options found on the command line.
 
QStringList positionalArgumentList
 Arguments which did not belong to any option.
 
QStringList unknownOptionNames
 Names of options which were unknown.
 
QString description
 Application description.
 
QList< PositionalArgumentDefinitionpositionalArgumentDefinitions
 
QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode
 The parsing mode for "-abc".
 
QCommandLineParser::OptionsAfterPositionalArgumentsMode optionsAfterPositionalArgumentsMode
 How to parse "arg -option".
 
bool builtinVersionOption
 Whether addVersionOption was called.
 
bool builtinHelpOption
 Whether addHelpOption was called.
 
bool needsParsing
 True if parse() needs to be called.
 

Detailed Description

Definition at line 27 of file qcommandlineparser.cpp.

Constructor & Destructor Documentation

◆ QCommandLineParserPrivate()

QCommandLineParserPrivate::QCommandLineParserPrivate ( )
inline

Definition at line 30 of file qcommandlineparser.cpp.

Member Function Documentation

◆ aliases()

QStringList QCommandLineParserPrivate::aliases ( const QString & name) const

Definition at line 98 of file qcommandlineparser.cpp.

References QList< T >::at(), QHash< Key, T >::cend(), commandLineOptionList, QHash< QString, qsizetype >::const_iterator, QHash< Key, T >::constFind(), it, nameHash, QCommandLineOption::names(), qUtf16Printable, and qWarning.

Referenced by QCommandLineParser::isSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkParsed()

void QCommandLineParserPrivate::checkParsed ( const char * method)

Definition at line 597 of file qcommandlineparser.cpp.

References method, needsParsing, and qWarning.

Referenced by QCommandLineParser::isSet(), QCommandLineParser::optionNames(), QCommandLineParser::positionalArguments(), QCommandLineParser::unknownOptionNames(), QCommandLineParser::value(), and QCommandLineParser::values().

+ Here is the caller graph for this function:

◆ helpText()

QString QCommandLineParserPrivate::helpText ( bool includeQtOptions) const

Definition at line 1103 of file qcommandlineparser.cpp.

References QString::arg(), arg, QCoreApplication::arguments(), QLatin1StringView::chop(), commandLineOptionList, description, QCommandLineOption::HiddenFromHelp, QString::isEmpty(), optionNames, positionalArgumentDefinitions, qApp, qMax(), qMin(), QString::size(), text, and wrapText().

Referenced by QCommandLineParser::helpText(), and showHelp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

bool QCommandLineParserPrivate::parse ( const QStringList & args)

Parse the list of arguments args, and fills in optionNames, optionValuesHash, unknownOptionNames, positionalArguments, and errorText.

Any results from a previous parse operation are removed.

The parser will not look for further options once it encounters the option {–}; this does not include when {–} follows an option that requires a value.

Definition at line 672 of file qcommandlineparser.cpp.

References arg, args, argument, QList< T >::at(), QList< T >::begin(), QString::clear(), QHash< Key, T >::clear(), commandLineOptionList, QHash< QString, qsizetype >::const_iterator, QHash< Key, T >::constEnd(), QHash< Key, T >::constFind(), QList< T >::end(), error, errorText, QString::isEmpty(), QList< T >::isEmpty(), nameHash, needsParsing, optionNames, optionsAfterPositionalArgumentsMode, optionValuesHash, QCommandLineParser::ParseAsCompactedShortOptions, QCommandLineParser::ParseAsLongOptions, QCommandLineParser::ParseAsPositionalArguments, parseOptionValue(), pos, positionalArgumentList, Q_ASSERT, qWarning, registerFoundOption(), QCommandLineOption::ShortOptionStyle, singleDashWordOptionMode, unknownOptionNames, and QCommandLineOption::valueName().

Referenced by QCommandLineParser::parse(), and QCommandLineParser::process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseOptionValue()

bool QCommandLineParserPrivate::parseOptionValue ( const QString & optionName,
const QString & argument,
QStringList::const_iterator * argumentIterator,
QStringList::const_iterator argsEnd )

Parse the value for a given option, if it was defined to expect one.

The value is taken from the next argument, or after the equal sign in argument.

Parameters
optionNamethe short option name
argumentthe argument from the command line currently parsed. Only used for -k=value parsing.
argumentIteratoriterator to the currently parsed argument. Incremented if the next argument contains the value.
argsEndargs.end(), to check if ++argumentIterator goes out of bounds Returns true on success.

Definition at line 631 of file qcommandlineparser.cpp.

References QString::arg(), argument, QList< T >::at(), commandLineOptionList, QHash< QString, qsizetype >::const_iterator, QHash< Key, T >::constEnd(), QHash< Key, T >::constFind(), errorText, QString::isEmpty(), nameHash, optionValuesHash, and QCommandLineOption::valueName().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerFoundOption()

bool QCommandLineParserPrivate::registerFoundOption ( const QString & optionName)

Looks up the option optionName (found on the command line) and register it as found. Returns true on success.

Definition at line 608 of file qcommandlineparser.cpp.

References QHash< Key, T >::contains(), nameHash, optionNames, and unknownOptionNames.

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showHelp()

Q_NORETURN void QCommandLineParserPrivate::showHelp ( int exitCode,
bool includeQtOptions )

Definition at line 1023 of file qcommandlineparser.cpp.

References helpText(), qt_call_post_routines(), showParserMessage(), and UsageMessage.

Referenced by QCommandLineParser::process(), and QCommandLineParser::showHelp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ builtinHelpOption

bool QCommandLineParserPrivate::builtinHelpOption

Whether addHelpOption was called.

Definition at line 91 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::addHelpOption(), and QCommandLineParser::process().

◆ builtinVersionOption

bool QCommandLineParserPrivate::builtinVersionOption

Whether addVersionOption was called.

Definition at line 88 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::addVersionOption(), and QCommandLineParser::process().

◆ commandLineOptionList

QList<QCommandLineOption> QCommandLineParserPrivate::commandLineOptionList

The command line options used for parsing.

Definition at line 52 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::addOption(), aliases(), helpText(), parse(), parseOptionValue(), and QCommandLineParser::values().

◆ description

QString QCommandLineParserPrivate::description

◆ errorText

QString QCommandLineParserPrivate::errorText

Error text set when parse() returns false.

Definition at line 49 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::errorText(), parse(), and parseOptionValue().

◆ nameHash

NameHash_t QCommandLineParserPrivate::nameHash

Hash mapping option names to their offsets in commandLineOptionList and optionArgumentList.

Definition at line 55 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::addOption(), aliases(), parse(), parseOptionValue(), registerFoundOption(), and QCommandLineParser::values().

◆ needsParsing

bool QCommandLineParserPrivate::needsParsing

True if parse() needs to be called.

Definition at line 94 of file qcommandlineparser.cpp.

Referenced by checkParsed(), and parse().

◆ optionNames

QStringList QCommandLineParserPrivate::optionNames

Names of options found on the command line.

Definition at line 61 of file qcommandlineparser.cpp.

Referenced by helpText(), QCommandLineParser::isSet(), QCommandLineParser::optionNames(), parse(), and registerFoundOption().

◆ optionsAfterPositionalArgumentsMode

QCommandLineParser::OptionsAfterPositionalArgumentsMode QCommandLineParserPrivate::optionsAfterPositionalArgumentsMode

How to parse "arg -option".

Definition at line 85 of file qcommandlineparser.cpp.

Referenced by parse(), and QCommandLineParser::setOptionsAfterPositionalArgumentsMode().

◆ optionValuesHash

QHash<qsizetype, QStringList> QCommandLineParserPrivate::optionValuesHash

Option values found (only for options with a value)

Definition at line 58 of file qcommandlineparser.cpp.

Referenced by parse(), parseOptionValue(), and QCommandLineParser::values().

◆ positionalArgumentDefinitions

QList<PositionalArgumentDefinition> QCommandLineParserPrivate::positionalArgumentDefinitions

◆ positionalArgumentList

QStringList QCommandLineParserPrivate::positionalArgumentList

Arguments which did not belong to any option.

Definition at line 64 of file qcommandlineparser.cpp.

Referenced by parse(), and QCommandLineParser::positionalArguments().

◆ singleDashWordOptionMode

QCommandLineParser::SingleDashWordOptionMode QCommandLineParserPrivate::singleDashWordOptionMode

The parsing mode for "-abc".

Definition at line 82 of file qcommandlineparser.cpp.

Referenced by parse(), and QCommandLineParser::setSingleDashWordOptionMode().

◆ unknownOptionNames

QStringList QCommandLineParserPrivate::unknownOptionNames

Names of options which were unknown.

Definition at line 67 of file qcommandlineparser.cpp.

Referenced by QCommandLineParser::errorText(), parse(), registerFoundOption(), and QCommandLineParser::unknownOptionNames().


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