refactor: move remoteHost to coreArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
a78959e66f
commit
6fa8ba087a
@ -37,11 +37,6 @@ bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char
|
||||
} else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) {
|
||||
// ignore -- included for backwards compatibility
|
||||
} else {
|
||||
if (i + 1 == argc) {
|
||||
args.m_serverAddress = argv[i];
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_CRIT("%s: unrecognized option `%s'" BYE, "deskflow-core", argv[i], "deskflow-core");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -81,9 +81,10 @@ void ClientApp::parseArgs(int argc, const char *const *argv)
|
||||
}
|
||||
} else {
|
||||
// save server address
|
||||
if (!args().m_serverAddress.empty()) {
|
||||
if (!Settings::value(Settings::Client::RemoteHost).isNull()) {
|
||||
try {
|
||||
*m_serverAddress = NetworkAddress(args().m_serverAddress, kDefaultPort);
|
||||
*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.
|
||||
|
||||
@ -17,11 +17,5 @@ public:
|
||||
ClientArgs();
|
||||
|
||||
~ClientArgs() override = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief m_serverAddress stores deskflow server address
|
||||
*/
|
||||
std::string m_serverAddress;
|
||||
};
|
||||
} // namespace deskflow
|
||||
|
||||
@ -138,6 +138,10 @@ void CoreArgParser::parse()
|
||||
(m_parser.value(CoreArgs::invertScrollOption) == "1"));
|
||||
Settings::setValue(Settings::Client::InvertScrollDirection, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::remoteHostOption)) {
|
||||
Settings::setValue(Settings::Client::RemoteHost, m_parser.value(CoreArgs::remoteHostOption));
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
|
||||
@ -77,9 +77,12 @@ struct CoreArgs
|
||||
"invertScrollDirection", "Client Mode: Set scroll direciton to be inverted (default: false)", "value"
|
||||
);
|
||||
|
||||
inline static const auto remoteHostOption =
|
||||
QCommandLineOption("remoteHost", "Client Mode: Sets the remote host in the settings file", "hostname");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption, logFileOption,
|
||||
secureOption, tlsCertOption, preventSleepOption, restartOption,
|
||||
displayOption, useHooksOption, peerCheckOption, serverConfigOption,
|
||||
yscrollOption, languageSyncOption, invertScrollOption};
|
||||
yscrollOption, languageSyncOption, invertScrollOption, remoteHostOption};
|
||||
};
|
||||
|
||||
@ -479,14 +479,6 @@ bool CoreProcess::addClientArgs(QStringList &args)
|
||||
args << "--log" << Settings::value(Settings::Log::File).toString();
|
||||
}
|
||||
|
||||
if (correctedAddress().isEmpty()) {
|
||||
Q_EMIT error(Error::AddressMissing);
|
||||
qDebug("address is missing for client args");
|
||||
return false;
|
||||
}
|
||||
|
||||
args << correctedAddress() + ":" + Settings::value(Settings::Core::Port).toString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -164,22 +164,12 @@ void ArgParserTests::assembleCommand()
|
||||
void ArgParserTests::clientArgs()
|
||||
{
|
||||
deskflow::ClientArgs args;
|
||||
char const *argv[] = {kAppId, "--help", "--res-w", "888", "127.0.0.1"};
|
||||
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_setAddress()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
const int argc = 2;
|
||||
const char *kAddressCmd[argc] = {"stub", "mock_address"};
|
||||
|
||||
QVERIFY(m_parser.parseClientArgs(clientArgs, argc, kAddressCmd));
|
||||
QCOMPARE(clientArgs.m_serverAddress, "mock_address");
|
||||
}
|
||||
|
||||
void ArgParserTests::client_badArgs()
|
||||
{
|
||||
deskflow::ClientArgs clientArgs;
|
||||
|
||||
@ -22,7 +22,6 @@ private Q_SLOTS:
|
||||
void getArgv();
|
||||
void assembleCommand();
|
||||
void clientArgs();
|
||||
void client_setAddress();
|
||||
void client_badArgs();
|
||||
void deprecatedArg_crypoPass_true();
|
||||
void deprecatedArg_crypoPass_false();
|
||||
|
||||
@ -410,6 +410,16 @@ void CoreArgParserTests::client_invertScrolling_0()
|
||||
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::client_remoteHost()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--remoteHost", "127.0.0.1"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE("127.0.0.1", Settings::value(Settings::Client::RemoteHost).toString());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
||||
|
||||
@ -54,6 +54,7 @@ private Q_SLOTS:
|
||||
void client_invertScrolling_false();
|
||||
void client_invertScrolling_1();
|
||||
void client_invertScrolling_0();
|
||||
void client_remoteHost();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
|
||||
Reference in New Issue
Block a user