1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef COMMANDPARSER_H
6#define COMMANDPARSER_H
7
8#include <QObject>
9
10QT_BEGIN_NAMESPACE
11class QCommandLineParser;
12class QCoreApplication;
13class QCommandLineOption;
14QT_END_NAMESPACE
15
16class CommandParser : public QObject
17{
18 Q_OBJECT
19 Q_DISABLE_COPY(CommandParser)
20
21public:
22 enum CommandModel {
23 Normal,
24 CommandLine
25 };
26
27 static CommandParser &instance();
28
29 bool isSet(const QString &name) const;
30 QString value(const QString &name) const;
31 void process();
32 void process(const QStringList &arguments);
33 void setModel(CommandModel model);
34 CommandModel getModel();
35 bool isBuildModel();
36
37private:
38 void initialize();
39 void initOptions();
40 void addOption(const QCommandLineOption &option);
41
42 QStringList positionalArguments() const;
43 QStringList unknownOptionNames() const;
44
45private:
46 explicit CommandParser(QObject *parent = nullptr);
47
48private:
49 QCommandLineParser *commandParser = nullptr;
50 CommandModel commandModel = CommandModel::Normal;
51};
52
53#endif // COMMANDPARSER_H
54