mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-29 03:04:40 +00:00
added new help functions
This commit is contained in:
parent
72d461bac8
commit
5a971a5b21
@ -33,6 +33,7 @@ CONFIG(release, debug|release): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
helpdata.cpp \
|
||||||
quasarapp.cpp \
|
quasarapp.cpp \
|
||||||
params.cpp \
|
params.cpp \
|
||||||
locales.cpp \
|
locales.cpp \
|
||||||
@ -40,6 +41,7 @@ SOURCES += \
|
|||||||
global.cpp
|
global.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
helpdata.h \
|
||||||
quasarapp.h \
|
quasarapp.h \
|
||||||
quasarapp_global.h \
|
quasarapp_global.h \
|
||||||
params.h \
|
params.h \
|
||||||
|
44
helpdata.cpp
Normal file
44
helpdata.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "helpdata.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int MAX_LENGTH = 80;
|
||||||
|
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Options &charter) {
|
||||||
|
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
||||||
|
print(line.key(), line.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Charters &help) {
|
||||||
|
for (auto line = help.begin(); line != help.end(); ++line) {
|
||||||
|
std::string expander('-', MAX_LENGTH);
|
||||||
|
|
||||||
|
std::cout << line.key().toStdString()<< std::endl;
|
||||||
|
std::cout << expander << std::endl;
|
||||||
|
print(line.value());
|
||||||
|
std::cout << expander << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuasarAppUtils::Help::print(const QString &key, const QString &value) {
|
||||||
|
|
||||||
|
int keyLength = key.size() + 2;
|
||||||
|
std::cout << key.toStdString() << ": ";
|
||||||
|
|
||||||
|
std::string expander(' ', keyLength);
|
||||||
|
auto words = value.split(" ");
|
||||||
|
|
||||||
|
int currentLength = keyLength;
|
||||||
|
for (const auto& word : words) {
|
||||||
|
if (currentLength < MAX_LENGTH) {
|
||||||
|
std::cout << word.toStdString();
|
||||||
|
currentLength += 2 + word.size();
|
||||||
|
} else {
|
||||||
|
std::cout << std::endl << expander << ": ";
|
||||||
|
currentLength = keyLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuasarAppUtils::Help::setLineLength(int newLength) {
|
||||||
|
MAX_LENGTH = newLength;
|
||||||
|
}
|
38
helpdata.h
Normal file
38
helpdata.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef HELPDATA_H
|
||||||
|
#define HELPDATA_H
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
namespace QuasarAppUtils{
|
||||||
|
|
||||||
|
namespace Help {
|
||||||
|
typedef QHash<QString, QString> Options;
|
||||||
|
typedef QHash<QString, Options> Charters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief print - line of help
|
||||||
|
* @param key - option name
|
||||||
|
* @param value - description of option
|
||||||
|
*/
|
||||||
|
void print(const QString& key, const QString& value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief print = help Charter
|
||||||
|
* @param charter - charter of help
|
||||||
|
*/
|
||||||
|
void print(const Options& charter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief print - all help
|
||||||
|
* @param help - help for printing
|
||||||
|
*/
|
||||||
|
void print(const Charters& help);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setLineLength - sets new length of helps line
|
||||||
|
* @param newLength - new size
|
||||||
|
*/
|
||||||
|
void setLineLength(int newLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // HELPDATA_H
|
27
params.cpp
27
params.cpp
@ -63,16 +63,15 @@ void Params::verboseLog(const QString &log, VerboseLvl vLvl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Params::getparamsHelp() {
|
Help::Charters Params::getparamsHelp() {
|
||||||
return
|
return {
|
||||||
{
|
{
|
||||||
{""},
|
"Base Options", {
|
||||||
{ " -verbose (level 1 - 3) : Shows debug log"},
|
{"-verbose (level 1 - 3)", "Shows debug log"},
|
||||||
{ " -fileLog (path to file) : Sets path of log file"},
|
{"-fileLog (path to file)", "Sets path of log file. Default it is path to executable file with suffix '.log'"},
|
||||||
{ " : Default it is path to executable file"},
|
{"noWriteInFileLog", "Disables loging into file"}
|
||||||
{ " : with suffix '.log' "},
|
}
|
||||||
{ " noWriteInFileLog : Disables loging into file"},
|
}
|
||||||
{ ""}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +81,14 @@ void Params::showHelp(const QStringList &help) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Params::showHelp(const Help::Charters &help) {
|
||||||
|
Help::print(help);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Params::showHelp() {
|
||||||
|
Help::print(getparamsHelp());
|
||||||
|
}
|
||||||
|
|
||||||
int Params::size() {
|
int Params::size() {
|
||||||
return params.size();
|
return params.size();
|
||||||
}
|
}
|
||||||
|
15
params.h
15
params.h
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include "quasarapp_global.h"
|
#include "quasarapp_global.h"
|
||||||
|
#include "helpdata.h"
|
||||||
|
|
||||||
namespace QuasarAppUtils {
|
namespace QuasarAppUtils {
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ public:
|
|||||||
* @brief getparamsHelp
|
* @brief getparamsHelp
|
||||||
* @return help string of default params
|
* @return help string of default params
|
||||||
*/
|
*/
|
||||||
static QStringList getparamsHelp();
|
static Help::Charters getparamsHelp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief showHelp - show all strings of help
|
* @brief showHelp - show all strings of help
|
||||||
@ -104,6 +104,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void showHelp(const QStringList& help);
|
static void showHelp(const QStringList& help);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief showHelp - show structe of help value
|
||||||
|
* @param help
|
||||||
|
*/
|
||||||
|
static void showHelp(const Help::Charters& help);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief size
|
* @brief size
|
||||||
* @return size of all params array
|
* @return size of all params array
|
||||||
@ -115,6 +121,11 @@ public:
|
|||||||
* @return size of params entered in conosole
|
* @return size of params entered in conosole
|
||||||
*/
|
*/
|
||||||
static int customParamasSize();
|
static int customParamasSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief showHelp - show base help section of QuasarAppLib
|
||||||
|
*/
|
||||||
|
static void showHelp();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user