-
Notifications
You must be signed in to change notification settings - Fork 2
/
params.h
261 lines (222 loc) · 9.04 KB
/
params.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* Copyright (C) 2018-2024 QuasarApp.
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#ifndef PARAMS_H
#define PARAMS_H
#include <QMap>
#include <QVariant>
#include "quasarapp_global.h"
#include "helpdata.h"
#include "optiondata.h"
namespace QuasarAppUtils {
/**
* @brief The VerboseLvl enum uses for sets log level.
*/
enum VerboseLvl {
/// Error message. This logs will marked as a **Error** and printing if the verbose lvl >= 0
Error = 0x0,
/// Warning message. This logs will marked as a **Warning** and printing if the verbose lvl >= 1
Warning = 0x1,
/// General information. This logs will marked as a **Info** and and printing if the verbose lvl >= 2.
Info = 0x2,
/// Debug message. This logs will marked as a **Debug** and printing if the verbose lvl >= 3
Debug = 0x3,
};
#ifdef QA_DISABLE_LOG
#define DEFAULT_VERBOSE_LVL "0"
#else
#ifdef QT_DEBUG
#define DEFAULT_VERBOSE_LVL "3"
#else
#define DEFAULT_VERBOSE_LVL "2"
#endif
#endif
/**
* @brief The Params class Contains fonctions for working with input arguments and logs.
* This Class support next comandline arguments.
* * **-verbose** (level 1 - 3) Shows debug log
* * **-fileLog** (path to file) Sets path of log file. Default it is path to executable file with suffix '.log'
*
* ### Usage
*
* ```cpp
#include <quasarapp.h>
if (!QuasarAppUtils::Params::parseParams(argc, argv)) {
QuasarAppUtils::Params::log("Warning message", QuasarAppUtils::Warning);
QuasarAppUtils::Params::showHelp();
exit(0);
}
```
*/
class QUASARAPPSHARED_EXPORT Params
{
public:
Params() = delete;
/**
* @brief parseParams Parse input data of started application.
* @param argc Count of arguments.
* @param argv Array of arguments.
* @param options This is list of the available options for parse. See the OptionData class for more inforamtion.
* If you skip thi argument then QuasarAppLib will not check input options.
* @return true if all arguments read successful else false.
*/
static bool parseParams(const int argc, const char *argv[], const OptionsDataList& options = {});
/**
* @brief parseParams Parse input data of started application.
* @param argc Count of arguments.
* @param argv Array of arguments.
* @param options This is list of the available options for parse. See the OptionData class for more inforamtion.
* If you skip thi argument then QuasarAppLib will not check input options.
* @return true if all arguments read successful else false.
*/
static bool parseParams(int argc, char *argv[], const OptionsDataList& options = {});
/**
* @brief parseParams Parse input data of started application.
* @param paramsArray Arguments.
* @param options This is list of the available options for parse. See the OptionData class for more inforamtion.
* If you skip thi argument then QuasarAppLib will not check input options.
* @return true if all arguments read successful else false.
*/
static bool parseParams(const QStringList& paramsArray, const OptionsDataList& options = {});
/**
* @brief getArg return string value of a @a key if key is exits else return a @a def value.
* If a @a def value not defined retunr empty string.
* @param key This is key of a console argument.
* @param def This is Default value. If key not exits This function will return a default value.
* @return a string value of argument.
*/
static QString getArg(const QString& key, const QString &def = {});
/**
* @brief setArg sets a new value of a @a key.
* @param key This is a name of sets option.
* @param val This is a new value of the @a key.
*/
static void setArg(const QString& key, const QString& val);
/**
* @brief setArg This method sets boolean value of key.
* @param key This is name of the console option.
* @param enable New value of key.
* @note For check is enable @a key argument use the Params::isEndable method.
*/
static void setEnable(const QString& key, bool enable);
/**
* @brief isEndable This method check if enable a @a key argument.
* @param key This is name of the validate arguments
* @return true if argument enabled.
*/
static bool isEndable(const QString& key);
/**
* @brief log This method print @a log text on console.
* @param log This is printed text message.
* @param vLvl This is verbose level of message, for get more information see the QuasarAppUtils::VerboseLvl enum.
* @note All messages will be printed according to the current verbose setting.
* @note The verbose level sets by verbose option on console.
*/
[[deprecated("Use QALogger and qt debug functions(qDebug, qInfo, qError...)")]]
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
/**
* @brief getVerboseLvl This method return the verbose log level.
* @return verbose log lvl.
*/
static VerboseLvl getVerboseLvl();
/**
* @brief isDebug This method return true if the application verbose level >= VerboseLvl::Debug.
* @return true if a verbose level >= VerboseLvl::Debug
*/
static bool isDebug();
/**
* @brief isDebugBuild This method return true if the library buildet in debug mode.
* @return true if this library buildet in debug mode.
*/
[[deprecated("Use Qt MACROSSSES")]]
static bool isDebugBuild();
/**
* @brief size This method return count of the all input arguments.
* @return size of all params array.
*/
static int size();
/**
* @brief showHelp This method shows all help message.
*/
static void showHelp();
/**
* @brief showHelpForInputOptions This method show help for each input option.
* @note Befor using of this method invoke the parseParams method. This is needed for generate the help message.
*
* **Example:**
*
* ```bash
* myTool help option1 -option2 argumets
* ```
*/
static void showHelpForInputOptions();
/**
* @brief getHelpOfInputOptions This method return help abut input options only. Exept help and h options.
* @return help abut input options only. Exept help and h options.
*/
static Help::Section getHelpOfInputOptions();
/**
* @brief getHelp This method return options help page.
* @note Befor using of this method invoke the parseParams method. This is needed for generate the help message.
* @return help of available options.
*/
static const Help::Section& getHelp();
/**
* @brief getUserParamsMap This method return const reference to the parsed arguments map.
* @return A map object with parsed arguments.
*/
static const QMap<QString, QString> &getUserParamsMap();
/**
* @brief clearParsedData This method clear all parsed data.
*/
static void clearParsedData();
/**
* @brief getCurrentExecutable This method return path to the current executable.
* @return path to current executable.
*/
static QString getCurrentExecutable();
/**
* @brief getCurrentExecutableDir This method return a path to a folder with the current executable.
* @return path of the folder with current executable.
*/
static QString getCurrentExecutableDir();
/**
* @brief availableArguments This method return list of the available arguments of QuasarAppLibrary
* @return list of the available arguments
*/
static OptionsDataList availableArguments();
private:
static bool optionsForEach(const QStringList& paramsArray,
const OptionsDataList &availableOptions);
/**
* @brief Traverse @a params and output its content (all the working
* options) to stdout in the form of option-value groups at the
* debug verbose level (-verbose 3).
*/
static void printWorkingOptions();
/**
* @brief checkOption return tru if the option is supported
* @param option checked option
* @return true if option is supported
*/
static bool checkOption(const OptionData &option, const QString &rawOptionName);
/**
* @brief parseAvailableOptions This is private method for parsing availabel options.
* @param availableOptionsListIn input data of the available options.
* @param availableOptionsListOut hash of available options wher key it options name and value it is options data
* @param helpOut This is help object that generated from the
*/
static void parseAvailableOptions(const OptionsDataList& availableOptionsListIn,
OptionsDataList* availableOptionsListOut,
Help::Section* helpOut);
static QMap<QString, QString> params;
static OptionsDataList inputOptions;
static Help::Section userHelp;
static QString appPath;
static QString appName;
};
}
#endif // PARAMS_H