refactor: deskflow-core take over --version arg for App class
change the serverAppTest to not call version
This commit is contained in:
parent
10f34f214f
commit
5e02adc772
7 changed files with 14 additions and 46 deletions
|
|
@ -66,18 +66,6 @@ App::~App()
|
||||||
delete m_args;
|
delete m_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::version()
|
|
||||||
{
|
|
||||||
const auto kBufferLength = 1024;
|
|
||||||
std::vector<char> buffer(kBufferLength);
|
|
||||||
std::snprintf( // NOSONAR
|
|
||||||
buffer.data(), kBufferLength, "%s v%s, protocol v%d.%d\n%s", //
|
|
||||||
argsBase().m_pname, kDisplayVersion, kProtocolMajorVersion, kProtocolMinorVersion, kCopyright
|
|
||||||
);
|
|
||||||
|
|
||||||
std::cout << std::string(buffer.data()) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int App::run(int argc, char **argv)
|
int App::run(int argc, char **argv)
|
||||||
{
|
{
|
||||||
#if MAC_OS_X_VERSION_10_7
|
#if MAC_OS_X_VERSION_10_7
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ public:
|
||||||
virtual const char *daemonInfo() const = 0;
|
virtual const char *daemonInfo() const = 0;
|
||||||
virtual std::string configSection() const = 0;
|
virtual std::string configSection() const = 0;
|
||||||
|
|
||||||
virtual void version();
|
|
||||||
void setByeFunc(void (*bye)(int)) override
|
void setByeFunc(void (*bye)(int)) override
|
||||||
{
|
{
|
||||||
m_bye = bye;
|
m_bye = bye;
|
||||||
|
|
@ -142,8 +141,7 @@ constexpr static auto s_helpGeneralArgs = //
|
||||||
" --tls-cert specify the path to the TLS certificate file.\n";
|
" --tls-cert specify the path to the TLS certificate file.\n";
|
||||||
|
|
||||||
constexpr static auto s_helpVersionArgs = //
|
constexpr static auto s_helpVersionArgs = //
|
||||||
" -h, --help display this help and exit.\n"
|
" -h, --help display this help and exit.\n";
|
||||||
" --version display version information and exit.\n";
|
|
||||||
|
|
||||||
constexpr static auto s_helpCommonArgs = //
|
constexpr static auto s_helpCommonArgs = //
|
||||||
" [--name <screen-name>]"
|
" [--name <screen-name>]"
|
||||||
|
|
|
||||||
|
|
@ -145,11 +145,6 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
|
||||||
m_app->help();
|
m_app->help();
|
||||||
}
|
}
|
||||||
argsBase().m_shouldExitOk = true;
|
argsBase().m_shouldExitOk = true;
|
||||||
} else if (isArg(i, argc, argv, nullptr, "--version")) {
|
|
||||||
if (m_app) {
|
|
||||||
m_app->version();
|
|
||||||
}
|
|
||||||
argsBase().m_shouldExitOk = true;
|
|
||||||
} else if (isArg(i, argc, argv, nullptr, "--server")) {
|
} else if (isArg(i, argc, argv, nullptr, "--server")) {
|
||||||
// HACK: stop error happening when using portable (deskflowp)
|
// HACK: stop error happening when using portable (deskflowp)
|
||||||
} else if (isArg(i, argc, argv, nullptr, "--client")) {
|
} else if (isArg(i, argc, argv, nullptr, "--client")) {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@
|
||||||
#include "common/Constants.h"
|
#include "common/Constants.h"
|
||||||
#include "common/ExitCodes.h"
|
#include "common/ExitCodes.h"
|
||||||
#include "common/Settings.h"
|
#include "common/Settings.h"
|
||||||
|
#include "deskflow/ProtocolTypes.h"
|
||||||
|
|
||||||
const QString CoreArgParser::s_headerText = QStringLiteral("%1-core: %2\n").arg(kAppId, kDisplayVersion);
|
const QString CoreArgParser::s_appName = QStringLiteral("%1-core").arg(kAppId);
|
||||||
|
const QString CoreArgParser::s_headerText = QStringLiteral("%1: %2\n").arg(s_appName, kDisplayVersion);
|
||||||
|
|
||||||
CoreArgParser::CoreArgParser(const QStringList &args)
|
CoreArgParser::CoreArgParser(const QStringList &args)
|
||||||
{
|
{
|
||||||
|
|
@ -61,7 +63,11 @@ QString CoreArgParser::helpText() const
|
||||||
|
|
||||||
QString CoreArgParser::versionText() const
|
QString CoreArgParser::versionText() const
|
||||||
{
|
{
|
||||||
return QStringLiteral("%1%2\n").arg(s_headerText, kCopyright);
|
const static auto vString = QStringLiteral("%1 v%2, protocol v%3.%4\n%5\n");
|
||||||
|
return vString.arg(
|
||||||
|
s_appName, kDisplayVersion, QString::number(kProtocolMajorVersion), QString::number(kProtocolMinorVersion),
|
||||||
|
kCopyright
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CoreArgParser::errorText() const
|
QString CoreArgParser::errorText() const
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,6 @@ private:
|
||||||
QString m_helpText;
|
QString m_helpText;
|
||||||
bool m_clientMode = false;
|
bool m_clientMode = false;
|
||||||
bool m_serverMode = false;
|
bool m_serverMode = false;
|
||||||
|
static const QString s_appName;
|
||||||
static const QString s_headerText;
|
static const QString s_headerText;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,31 +10,11 @@
|
||||||
#include "deskflow/ServerApp.h"
|
#include "deskflow/ServerApp.h"
|
||||||
#include "deskflow/ServerArgs.h"
|
#include "deskflow/ServerArgs.h"
|
||||||
|
|
||||||
#include <iostream>
|
void ServerAppTests::section()
|
||||||
|
|
||||||
class MockServerApp : public ServerApp
|
|
||||||
{
|
{
|
||||||
public:
|
ServerApp app(nullptr);
|
||||||
MockServerApp() : ServerApp(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void ServerAppTests::version()
|
|
||||||
{
|
|
||||||
MockServerApp app;
|
|
||||||
QVERIFY(!app.args().m_config);
|
QVERIFY(!app.args().m_config);
|
||||||
|
QCOMPARE(app.configSection(), "server");
|
||||||
std::stringstream buffer;
|
|
||||||
std::streambuf *old = std::cout.rdbuf(buffer.rdbuf());
|
|
||||||
|
|
||||||
app.version();
|
|
||||||
|
|
||||||
std::cout.rdbuf(old);
|
|
||||||
|
|
||||||
static QRegularExpression yearReg(".*[0-9]{4}-[0-9]{4} Deskflow Devs.*");
|
|
||||||
auto result = yearReg.match(QString::fromLatin1(buffer.str()));
|
|
||||||
QVERIFY(result.hasMatch());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(ServerAppTests)
|
QTEST_MAIN(ServerAppTests)
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ class ServerAppTests : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
// Test are run in order top to bottom
|
// Test are run in order top to bottom
|
||||||
void version();
|
void section();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue