refactor: remove ClientArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
6fa8ba087a
commit
37827f0540
@ -9,7 +9,6 @@
|
||||
#include "base/Log.h"
|
||||
#include "deskflow/App.h"
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
|
||||
#ifdef WINAPI_MSWINDOWS
|
||||
#include <VersionHelpers.h>
|
||||
@ -24,38 +23,6 @@ ArgParser::ArgParser(App *app) : m_app(app)
|
||||
{
|
||||
}
|
||||
|
||||
bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv) const
|
||||
{
|
||||
setArgsBase(args);
|
||||
|
||||
int i{1};
|
||||
while (i < argc) {
|
||||
if (parseGenericArgs(argc, argv, i) || parseDeprecatedArgs(argc, argv, i) ||
|
||||
isArg(i, argc, argv, nullptr, "client")) {
|
||||
++i;
|
||||
continue;
|
||||
} else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) {
|
||||
// ignore -- included for backwards compatibility
|
||||
} else {
|
||||
LOG_CRIT("%s: unrecognized option `%s'" BYE, "deskflow-core", argv[i], "deskflow-core");
|
||||
return false;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
// exactly one non-option argument (server-address)
|
||||
if (i == argc && !args.m_shouldExitFail && !args.m_shouldExitOk) {
|
||||
LOG_CRIT("%s: a server address or name is required" BYE, "deskflow-core", "deskflow-core");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checkUnexpectedArgs()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) const
|
||||
{
|
||||
if (isArg(i, argc, argv, "-h", "--help")) {
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
namespace deskflow {
|
||||
class ArgsBase;
|
||||
class ServerArgs;
|
||||
class ClientArgs;
|
||||
} // namespace deskflow
|
||||
|
||||
class App;
|
||||
@ -23,7 +22,6 @@ class ArgParser
|
||||
public:
|
||||
explicit ArgParser(App *app);
|
||||
|
||||
bool parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv) const;
|
||||
bool parseGenericArgs(int argc, const char *const *argv, int &i) const;
|
||||
bool parseDeprecatedArgs(int argc, const char *const *argv, int &i) const;
|
||||
void setArgsBase(deskflow::ArgsBase &argsBase) const
|
||||
|
||||
@ -74,8 +74,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
||||
Chunk.h
|
||||
ClientApp.cpp
|
||||
ClientApp.h
|
||||
ClientArgs.cpp
|
||||
ClientArgs.h
|
||||
ClipboardTypes.h
|
||||
Clipboard.cpp
|
||||
Clipboard.h
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#include "common/ExitCodes.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/ArgParser.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
#include "deskflow/Screen.h"
|
||||
#include "deskflow/ScreenException.h"
|
||||
@ -63,39 +63,28 @@
|
||||
constexpr static auto s_retryTime = 1.0;
|
||||
|
||||
ClientApp::ClientApp(IEventQueue *events, const QString &processName)
|
||||
: App(events, processName, new deskflow::ClientArgs())
|
||||
: App(events, processName, new deskflow::ArgsBase())
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ClientApp::parseArgs(int argc, const char *const *argv)
|
||||
void ClientApp::parseArgs(int, const char *const *)
|
||||
{
|
||||
ArgParser argParser(this);
|
||||
bool result = argParser.parseClientArgs(args(), argc, argv);
|
||||
|
||||
if (!result || args().m_shouldExitOk || args().m_shouldExitFail) {
|
||||
if (args().m_shouldExitOk) {
|
||||
bye(s_exitSuccess);
|
||||
} else {
|
||||
bye(s_exitArgs);
|
||||
}
|
||||
} else {
|
||||
// save server address
|
||||
if (!Settings::value(Settings::Client::RemoteHost).isNull()) {
|
||||
try {
|
||||
*m_serverAddress =
|
||||
NetworkAddress(Settings::value(Settings::Client::RemoteHost).toString().toStdString(), kDefaultPort);
|
||||
m_serverAddress->resolve();
|
||||
} catch (SocketAddressException &e) {
|
||||
// allow an address that we can't look up if we're restartable.
|
||||
// we'll try to resolve the address each time we connect to the
|
||||
// server. a bad port will never get better. patch by Brent
|
||||
// Priddy.
|
||||
if (!Settings::value(Settings::Core::RestartOnFailure).toBool() ||
|
||||
e.getError() == SocketAddressException::SocketError::BadPort) {
|
||||
LOG_CRIT("%s: %s" BYE, qPrintable(processName()), e.what(), qPrintable(processName()));
|
||||
bye(s_exitFailed);
|
||||
}
|
||||
// save server address
|
||||
if (!Settings::value(Settings::Client::RemoteHost).isNull()) {
|
||||
try {
|
||||
*m_serverAddress =
|
||||
NetworkAddress(Settings::value(Settings::Client::RemoteHost).toString().toStdString(), kDefaultPort);
|
||||
m_serverAddress->resolve();
|
||||
} catch (SocketAddressException &e) {
|
||||
// allow an address that we can't look up if we're restartable.
|
||||
// we'll try to resolve the address each time we connect to the
|
||||
// server. a bad port will never get better. patch by Brent
|
||||
// Priddy.
|
||||
if (!Settings::value(Settings::Core::RestartOnFailure).toBool() ||
|
||||
e.getError() == SocketAddressException::SocketError::BadPort) {
|
||||
LOG_CRIT("%s: %s" BYE, qPrintable(processName()), e.what(), qPrintable(processName()));
|
||||
bye(s_exitFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public:
|
||||
// IApp overrides
|
||||
//
|
||||
|
||||
void parseArgs(int argc, const char *const *argv) override;
|
||||
void parseArgs(int, const char *const *) override;
|
||||
void help() override;
|
||||
const char *daemonName() const override;
|
||||
const char *daemonInfo() const override;
|
||||
@ -78,11 +78,6 @@ public:
|
||||
return m_client;
|
||||
}
|
||||
|
||||
deskflow::ClientArgs &args() const
|
||||
{
|
||||
return (deskflow::ClientArgs &)argsBase();
|
||||
}
|
||||
|
||||
//
|
||||
// Static functions
|
||||
//
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "ClientArgs.h"
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
ClientArgs::ClientArgs()
|
||||
{
|
||||
m_classType = ClassType::Client;
|
||||
}
|
||||
} // namespace deskflow
|
||||
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ArgsBase.h"
|
||||
|
||||
namespace deskflow {
|
||||
class ClientArgs : public ArgsBase
|
||||
{
|
||||
|
||||
/// Public functions
|
||||
public:
|
||||
ClientArgs();
|
||||
|
||||
~ClientArgs() override = default;
|
||||
};
|
||||
} // namespace deskflow
|
||||
@ -7,8 +7,6 @@
|
||||
|
||||
#include "deskflow/KeyState.h"
|
||||
#include "base/Log.h"
|
||||
#include "deskflow/ClientApp.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
#include "deskflow/IPlatformScreen.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/App.h"
|
||||
#include "deskflow/ArgParser.h"
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/Screen.h"
|
||||
#include "deskflow/ScreenException.h"
|
||||
#include "net/SocketException.h"
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "deskflow/ClientArgs.h"
|
||||
#include "deskflow/PlatformScreen.h"
|
||||
#include "platform/MSWindowsHook.h"
|
||||
#include "platform/MSWindowsPowerManager.h"
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "deskflow/App.h"
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/ClientApp.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
#include "deskflow/Clipboard.h"
|
||||
#include "deskflow/KeyMap.h"
|
||||
#include "deskflow/ScreenException.h"
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "arch/Arch.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
#include "deskflow/KeyMap.h"
|
||||
#include "deskflow/PlatformScreen.h"
|
||||
#include "platform/XDGPowerManager.h"
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
#include "ArgParserTests.h"
|
||||
|
||||
#include "deskflow/ArgsBase.h"
|
||||
#include "deskflow/ClientArgs.h"
|
||||
|
||||
// This file is generated at build time
|
||||
#include <common/Constants.h>
|
||||
@ -161,27 +160,6 @@ void ArgParserTests::assembleCommand()
|
||||
QCOMPARE(command, "\"stub1 space\" stub2 \"stub3 space\"");
|
||||
}
|
||||
|
||||
void ArgParserTests::clientArgs()
|
||||
{
|
||||
deskflow::ClientArgs args;
|
||||
char const *argv[] = {kAppId, "--help", "--res-w", "888"};
|
||||
|
||||
QVERIFY(m_parser.parseClientArgs(args, sizeof(argv) / sizeof(argv[0]), argv));
|
||||
QVERIFY(args.m_shouldExitOk);
|
||||
}
|
||||
|
||||
void ArgParserTests::client_badArgs()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
const int argc = 1;
|
||||
const char *kNoAddressCmd[argc] = {"stub"};
|
||||
QVERIFY(!m_parser.parseClientArgs(clientArgs, argc, kNoAddressCmd));
|
||||
|
||||
const int argc2 = 3;
|
||||
const char *kUnrecognizedCmd[argc2] = {"stub", "mock_arg", "mock_address"};
|
||||
QVERIFY(!m_parser.parseClientArgs(clientArgs, argc2, kUnrecognizedCmd));
|
||||
}
|
||||
|
||||
void ArgParserTests::deprecatedArg_crypoPass_true()
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
@ -21,8 +21,6 @@ private Q_SLOTS:
|
||||
void splitCommand();
|
||||
void getArgv();
|
||||
void assembleCommand();
|
||||
void clientArgs();
|
||||
void client_badArgs();
|
||||
void deprecatedArg_crypoPass_true();
|
||||
void deprecatedArg_crypoPass_false();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user