2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2021-01-05 13:04:05 +03:00
|
|
|
* Copyright (C) 2018-2021 QuasarApp.
|
2018-09-29 15:56:04 +03:00
|
|
|
* 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
|
|
|
|
|
2021-04-26 11:27:19 +03:00
|
|
|
#include <QMap>
|
2018-09-29 15:56:04 +03:00
|
|
|
#include <QVariant>
|
|
|
|
#include "quasarapp_global.h"
|
2020-02-18 22:28:17 +03:00
|
|
|
#include "helpdata.h"
|
2021-07-26 13:17:06 +03:00
|
|
|
#include "optiondata.h"
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
namespace QuasarAppUtils {
|
|
|
|
|
2021-07-26 13:17:06 +03:00
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief The VerboseLvl enum uses for sets log level.
|
2018-09-29 15:56:04 +03:00
|
|
|
*/
|
2019-03-28 18:58:36 +03:00
|
|
|
enum VerboseLvl {
|
2021-05-01 11:38:35 +03:00
|
|
|
/// Error message. This logs will marked as a **Error** and printing if the verbose lvl >= 0
|
2021-04-30 12:06:50 +03:00
|
|
|
Error = 0x0,
|
2021-05-01 11:38:35 +03:00
|
|
|
/// Warning message. This logs will marked as a **Warning** and printing if the verbose lvl >= 1
|
2021-04-30 12:06:50 +03:00
|
|
|
Warning = 0x1,
|
2021-05-01 11:38:35 +03:00
|
|
|
/// General information. This logs will marked as a **Info** and and printing if the verbose lvl >= 2.
|
2021-04-30 12:06:50 +03:00
|
|
|
Info = 0x2,
|
2021-04-26 12:01:08 +03:00
|
|
|
/// Debug message. This logs will marked as a **Debug** and printing if the verbose lvl >= 3
|
2020-04-14 17:57:54 +03:00
|
|
|
Debug = 0x3,
|
2020-04-04 15:42:56 +03:00
|
|
|
|
2019-03-28 18:58:36 +03:00
|
|
|
};
|
|
|
|
|
2021-07-22 11:28:35 +03:00
|
|
|
#ifdef QT_DEBUG
|
2020-08-25 15:33:38 +03:00
|
|
|
#define DEFAULT_VERBOSE_LVL "3"
|
2021-07-22 11:28:35 +03:00
|
|
|
#else
|
|
|
|
#define DEFAULT_VERBOSE_LVL "2"
|
2020-08-25 15:33:38 +03:00
|
|
|
#endif
|
2021-04-26 11:27:19 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The Params class Contains fonctions for working with input arguments and logs.
|
2021-04-26 12:01:08 +03:00
|
|
|
* 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'
|
2021-04-26 11:27:19 +03:00
|
|
|
*/
|
2018-09-29 15:56:04 +03:00
|
|
|
class QUASARAPPSHARED_EXPORT Params
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Params() = delete;
|
|
|
|
|
|
|
|
/**
|
2021-04-07 13:24:30 +03:00
|
|
|
* @brief parseParams Parse input data of started application.
|
|
|
|
* @param argc Count of arguments.
|
|
|
|
* @param argv Array of arguments.
|
2021-07-28 12:38:44 +03:00
|
|
|
* @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.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @return true if all arguments read successful else false.
|
2018-09-29 15:56:04 +03:00
|
|
|
*/
|
2021-07-28 12:38:44 +03:00
|
|
|
static bool parseParams(const int argc, const char *argv[], const OptionsDataList& options = {});
|
2021-04-26 11:27:19 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief parseParams Parse input data of started application.
|
|
|
|
* @param argc Count of arguments.
|
|
|
|
* @param argv Array of arguments.
|
2021-07-28 12:38:44 +03:00
|
|
|
* @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.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @return true if all arguments read successful else false.
|
|
|
|
*/
|
2021-07-28 12:38:44 +03:00
|
|
|
static bool parseParams(int argc, char *argv[], const OptionsDataList& options = {});
|
2019-11-21 18:03:13 +03:00
|
|
|
|
2019-09-10 18:22:13 +03:00
|
|
|
/**
|
2021-04-07 13:24:30 +03:00
|
|
|
* @brief parseParams Parse input data of started application.
|
|
|
|
* @param paramsArray Arguments.
|
2021-07-28 12:38:44 +03:00
|
|
|
* @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.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @return true if all arguments read successful else false.
|
2019-09-10 18:22:13 +03:00
|
|
|
*/
|
2021-07-28 12:38:44 +03:00
|
|
|
static bool parseParams(const QStringList& paramsArray, const OptionsDataList& options = {});
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @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.
|
2018-09-29 15:56:04 +03:00
|
|
|
*/
|
2021-03-26 17:18:29 +03:00
|
|
|
static QString getArg(const QString& key, const QString &def = {});
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2019-02-02 16:01:28 +03:00
|
|
|
/**
|
2021-04-26 12:05:48 +03:00
|
|
|
* @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.
|
2019-02-02 16:01:28 +03:00
|
|
|
*/
|
2021-03-26 17:18:29 +03:00
|
|
|
static void setArg(const QString& key, const QString& val);
|
2019-02-02 16:01:28 +03:00
|
|
|
|
|
|
|
/**
|
2021-04-26 21:17:59 +03:00
|
|
|
* @brief setArg This method sets boolean value of key.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @param key This is name of the console option.
|
2021-04-07 13:24:30 +03:00
|
|
|
* @param enable New value of key.
|
2021-04-26 11:36:15 +03:00
|
|
|
* @note For check is enable @a key argument use the Params::isEndable method.
|
2019-02-02 16:01:28 +03:00
|
|
|
*/
|
|
|
|
static void setEnable(const QString& key, bool enable);
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief isEndable This method check if enable a @a key argument.
|
|
|
|
* @param key This is name of the validate arguments
|
2021-04-07 13:24:30 +03:00
|
|
|
* @return true if argument enabled.
|
2018-09-29 15:56:04 +03:00
|
|
|
*/
|
|
|
|
static bool isEndable(const QString& key);
|
2019-01-02 13:42:51 +03:00
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief log This method print @a log text on console.
|
|
|
|
* @param log This is printed text message.
|
2021-04-26 11:36:15 +03:00
|
|
|
* @param vLvl This is verbose level of message, for get more information see the QuasarAppUtils::VerboseLvl enum.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @note All messages will be printed according to the current verbose setting.
|
|
|
|
* @note The verbose level sets by verbose option on console.
|
2019-01-02 13:42:51 +03:00
|
|
|
*/
|
2021-04-07 18:59:58 +03:00
|
|
|
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
2019-08-22 14:21:43 +03:00
|
|
|
|
2020-04-14 17:57:54 +03:00
|
|
|
/**
|
2021-03-26 17:18:29 +03:00
|
|
|
* @brief getVerboseLvl This method return the verbose log level.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @return verbose log lvl.
|
2020-04-14 17:57:54 +03:00
|
|
|
*/
|
|
|
|
static VerboseLvl getVerboseLvl();
|
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief isDebug This method return true if the application verbose level >= VerboseLvl::Debug.
|
|
|
|
* @return true if a verbose level >= VerboseLvl::Debug
|
2020-04-14 17:57:54 +03:00
|
|
|
*/
|
|
|
|
static bool isDebug();
|
|
|
|
|
2021-01-24 14:04:31 +03:00
|
|
|
/**
|
|
|
|
* @brief isDebugBuild This method return true if the library buildet in debug mode.
|
|
|
|
* @return true if this library buildet in debug mode.
|
|
|
|
*/
|
|
|
|
static bool isDebugBuild();
|
|
|
|
|
2019-09-16 12:38:10 +03:00
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief size This method return count of the all input arguments.
|
|
|
|
* @return size of all params array.
|
2019-09-16 12:38:10 +03:00
|
|
|
*/
|
|
|
|
static int size();
|
|
|
|
|
|
|
|
/**
|
2021-07-26 13:17:06 +03:00
|
|
|
* @brief showHelp This method shows all help message.
|
2021-07-28 12:38:44 +03:00
|
|
|
* @param option This is option key that needed show a help message.
|
2020-02-18 22:28:17 +03:00
|
|
|
*/
|
2021-07-28 12:38:44 +03:00
|
|
|
static void showHelp(const QString& option = "");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
2020-04-18 21:28:35 +03:00
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief getUserParamsMap This method return const reference to the parsed arguments map.
|
|
|
|
* @return A map object with parsed arguments.
|
2020-04-18 21:28:35 +03:00
|
|
|
*/
|
2021-04-26 11:27:19 +03:00
|
|
|
static const QMap<QString, QString> &getUserParamsMap();
|
2020-05-17 23:21:12 +03:00
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief clearParsedData This method clear all parsed data.
|
2020-05-17 23:21:12 +03:00
|
|
|
*/
|
|
|
|
static void clearParsedData();
|
|
|
|
|
|
|
|
/**
|
2021-04-26 11:27:19 +03:00
|
|
|
* @brief getCurrentExecutable This method return path to the current executable.
|
2020-05-17 23:21:12 +03:00
|
|
|
* @return path to current executable.
|
|
|
|
*/
|
|
|
|
static QString getCurrentExecutable();
|
2020-09-28 23:42:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief getCurrentExecutableDir This method return a path to a folder with the current executable.
|
2021-04-26 11:27:19 +03:00
|
|
|
* @return path of the folder with current executable.
|
2020-09-28 23:42:54 +03:00
|
|
|
*/
|
|
|
|
static QString getCurrentExecutableDir();
|
|
|
|
|
2021-07-27 17:24:43 +03:00
|
|
|
/**
|
|
|
|
* @brief availableArguments This method return list of the available arguments of QuasarAppLibrary
|
|
|
|
* @return list of the available arguments
|
|
|
|
*/
|
|
|
|
static OptionsDataList availableArguments();
|
|
|
|
|
2021-04-26 11:27:19 +03:00
|
|
|
private:
|
|
|
|
static QString timeString();
|
|
|
|
static std::string lvlToString(VerboseLvl vLvl);
|
|
|
|
static bool writeLoginFile(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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();
|
|
|
|
|
2021-07-28 12:38:44 +03:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
2021-07-26 13:17:06 +03:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
2021-04-26 11:27:19 +03:00
|
|
|
|
|
|
|
static QMap<QString, QString> params;
|
2021-07-28 12:38:44 +03:00
|
|
|
static OptionsDataList inputOptions;
|
|
|
|
|
2021-07-26 13:17:06 +03:00
|
|
|
static Help::Section userHelp;
|
2021-04-26 11:27:19 +03:00
|
|
|
static QString appPath;
|
|
|
|
static QString appName;
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PARAMS_H
|