QCommandLineParser: add support for hiding options from --help.
[ChangeLog][QtCore][QCommandLineParser] Added support for hiding options from the --help output, with QCommandLineOption::setHidden(true). Task-number: QTBUG-44298 Change-Id: I62cc2a55428365c0bcc79d2e47c72c0c92104e74 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
7e070d47e3
commit
4415fefcda
@ -42,6 +42,7 @@ class QCommandLineOptionPrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
inline QCommandLineOptionPrivate()
|
||||
: hidden(false)
|
||||
{ }
|
||||
|
||||
void setNames(const QStringList &nameList);
|
||||
@ -58,6 +59,9 @@ public:
|
||||
|
||||
//! The list of default values used for this option.
|
||||
QStringList defaultValues;
|
||||
|
||||
//! Show or hide in --help
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -362,4 +366,30 @@ QStringList QCommandLineOption::defaultValues() const
|
||||
return d->defaultValues;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether to hide this option in the user-visible help output.
|
||||
|
||||
All options are visible by default. Setting \a hidden to true for
|
||||
a particular option makes it internal, i.e. not listed in the help output.
|
||||
|
||||
\since 5.5
|
||||
\sa isHidden
|
||||
*/
|
||||
void QCommandLineOption::setHidden(bool hide)
|
||||
{
|
||||
d->hidden = hide;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns true if this option is omitted from the help output,
|
||||
false if the option is listed.
|
||||
|
||||
\since 5.5
|
||||
\sa setHidden()
|
||||
*/
|
||||
bool QCommandLineOption::isHidden() const
|
||||
{
|
||||
return d->hidden;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -77,6 +77,9 @@ public:
|
||||
void setDefaultValues(const QStringList &defaultValues);
|
||||
QStringList defaultValues() const;
|
||||
|
||||
void setHidden(bool hidden);
|
||||
bool isHidden() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QCommandLineOptionPrivate> d;
|
||||
};
|
||||
|
@ -1062,6 +1062,8 @@ QString QCommandLineParserPrivate::helpText() const
|
||||
++longestOptionNameString;
|
||||
for (int i = 0; i < commandLineOptionList.count(); ++i) {
|
||||
const QCommandLineOption &option = commandLineOptionList.at(i);
|
||||
if (option.isHidden())
|
||||
continue;
|
||||
text += wrapText(optionNameList.at(i), longestOptionNameString, option.description());
|
||||
}
|
||||
if (!positionalArgumentDefinitions.isEmpty()) {
|
||||
|
@ -73,6 +73,12 @@ int main(int argc, char *argv[])
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
parser.addOption(newlineOption);
|
||||
|
||||
// A hidden option
|
||||
QCommandLineOption hiddenOption(QStringList() << QStringLiteral("hidden"));
|
||||
hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR"));
|
||||
hiddenOption.setHidden(true);
|
||||
parser.addOption(hiddenOption);
|
||||
|
||||
// This program supports different options depending on the "command" (first argument).
|
||||
// Call parse() to find out the positional arguments.
|
||||
parser.parse(QCoreApplication::arguments());
|
||||
|
Loading…
Reference in New Issue
Block a user