refactor: deskflow-core take over --version arg for App class

change the serverAppTest to not call version
This commit is contained in:
sithlord48
2025-08-22 18:39:42 -04:00
committed by Chris Rizzitello
parent 10f34f214f
commit 5e02adc772
7 changed files with 14 additions and 46 deletions

View File

@ -66,18 +66,6 @@ App::~App()
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)
{
#if MAC_OS_X_VERSION_10_7

View File

@ -58,7 +58,6 @@ public:
virtual const char *daemonInfo() const = 0;
virtual std::string configSection() const = 0;
virtual void version();
void setByeFunc(void (*bye)(int)) override
{
m_bye = bye;
@ -142,8 +141,7 @@ constexpr static auto s_helpGeneralArgs = //
" --tls-cert specify the path to the TLS certificate file.\n";
constexpr static auto s_helpVersionArgs = //
" -h, --help display this help and exit.\n"
" --version display version information and exit.\n";
" -h, --help display this help and exit.\n";
constexpr static auto s_helpCommonArgs = //
" [--name <screen-name>]"

View File

@ -145,11 +145,6 @@ bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) cons
m_app->help();
}
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")) {
// HACK: stop error happening when using portable (deskflowp)
} else if (isArg(i, argc, argv, nullptr, "--client")) {

View File

@ -10,8 +10,10 @@
#include "common/Constants.h"
#include "common/ExitCodes.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)
{
@ -61,7 +63,11 @@ QString CoreArgParser::helpText() 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

View File

@ -40,5 +40,6 @@ private:
QString m_helpText;
bool m_clientMode = false;
bool m_serverMode = false;
static const QString s_appName;
static const QString s_headerText;
};

View File

@ -10,31 +10,11 @@
#include "deskflow/ServerApp.h"
#include "deskflow/ServerArgs.h"
#include <iostream>
class MockServerApp : public ServerApp
void ServerAppTests::section()
{
public:
MockServerApp() : ServerApp(nullptr)
{
}
};
void ServerAppTests::version()
{
MockServerApp app;
ServerApp app(nullptr);
QVERIFY(!app.args().m_config);
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());
QCOMPARE(app.configSection(), "server");
}
QTEST_MAIN(ServerAppTests)

View File

@ -11,5 +11,5 @@ class ServerAppTests : public QObject
Q_OBJECT
private Q_SLOTS:
// Test are run in order top to bottom
void version();
void section();
};