1 | // Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QCOMMANDLINEPARSER_H |
5 | #define QCOMMANDLINEPARSER_H |
6 | |
7 | #include <QtCore/qstringlist.h> |
8 | |
9 | #include <QtCore/qcoreapplication.h> |
10 | #include <QtCore/qcommandlineoption.h> |
11 | |
12 | QT_REQUIRE_CONFIG(commandlineparser); |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QCommandLineParserPrivate; |
17 | class QCoreApplication; |
18 | |
19 | class Q_CORE_EXPORT QCommandLineParser |
20 | { |
21 | Q_DECLARE_TR_FUNCTIONS(QCommandLineParser) |
22 | public: |
23 | QCommandLineParser(); |
24 | ~QCommandLineParser(); |
25 | |
26 | enum SingleDashWordOptionMode { |
27 | ParseAsCompactedShortOptions, |
28 | ParseAsLongOptions |
29 | }; |
30 | void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode); |
31 | |
32 | enum OptionsAfterPositionalArgumentsMode { |
33 | ParseAsOptions, |
34 | ParseAsPositionalArguments |
35 | }; |
36 | void setOptionsAfterPositionalArgumentsMode(OptionsAfterPositionalArgumentsMode mode); |
37 | |
38 | bool addOption(const QCommandLineOption &commandLineOption); |
39 | bool addOptions(const QList<QCommandLineOption> &options); |
40 | |
41 | QCommandLineOption addVersionOption(); |
42 | QCommandLineOption addHelpOption(); |
43 | void setApplicationDescription(const QString &description); |
44 | QString applicationDescription() const; |
45 | void addPositionalArgument(const QString &name, const QString &description, const QString &syntax = QString()); |
46 | void clearPositionalArguments(); |
47 | |
48 | void process(const QStringList &arguments); |
49 | void process(const QCoreApplication &app); |
50 | |
51 | bool parse(const QStringList &arguments); |
52 | QString errorText() const; |
53 | |
54 | bool isSet(const QString &name) const; |
55 | QString value(const QString &name) const; |
56 | QStringList values(const QString &name) const; |
57 | |
58 | bool isSet(const QCommandLineOption &option) const; |
59 | QString value(const QCommandLineOption &option) const; |
60 | QStringList values(const QCommandLineOption &option) const; |
61 | |
62 | QStringList positionalArguments() const; |
63 | QStringList optionNames() const; |
64 | QStringList unknownOptionNames() const; |
65 | |
66 | Q_NORETURN void showVersion(); |
67 | Q_NORETURN void showHelp(int exitCode = 0); |
68 | QString helpText() const; |
69 | |
70 | private: |
71 | Q_DISABLE_COPY(QCommandLineParser) |
72 | |
73 | QCommandLineParserPrivate * const d; |
74 | }; |
75 | |
76 | QT_END_NAMESPACE |
77 | |
78 | #endif // QCOMMANDLINEPARSER_H |
79 |