refactor: move remoteHost to coreArgs
This commit is contained in:
parent
a78959e66f
commit
6fa8ba087a
10 changed files with 23 additions and 34 deletions
|
|
@ -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")) {
|
} else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) {
|
||||||
// ignore -- included for backwards compatibility
|
// ignore -- included for backwards compatibility
|
||||||
} else {
|
} 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");
|
LOG_CRIT("%s: unrecognized option `%s'" BYE, "deskflow-core", argv[i], "deskflow-core");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,10 @@ void ClientApp::parseArgs(int argc, const char *const *argv)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// save server address
|
// save server address
|
||||||
if (!args().m_serverAddress.empty()) {
|
if (!Settings::value(Settings::Client::RemoteHost).isNull()) {
|
||||||
try {
|
try {
|
||||||
*m_serverAddress = NetworkAddress(args().m_serverAddress, kDefaultPort);
|
*m_serverAddress =
|
||||||
|
NetworkAddress(Settings::value(Settings::Client::RemoteHost).toString().toStdString(), kDefaultPort);
|
||||||
m_serverAddress->resolve();
|
m_serverAddress->resolve();
|
||||||
} catch (SocketAddressException &e) {
|
} catch (SocketAddressException &e) {
|
||||||
// allow an address that we can't look up if we're restartable.
|
// allow an address that we can't look up if we're restartable.
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,5 @@ public:
|
||||||
ClientArgs();
|
ClientArgs();
|
||||||
|
|
||||||
~ClientArgs() override = default;
|
~ClientArgs() override = default;
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief m_serverAddress stores deskflow server address
|
|
||||||
*/
|
|
||||||
std::string m_serverAddress;
|
|
||||||
};
|
};
|
||||||
} // namespace deskflow
|
} // namespace deskflow
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,10 @@ void CoreArgParser::parse()
|
||||||
(m_parser.value(CoreArgs::invertScrollOption) == "1"));
|
(m_parser.value(CoreArgs::invertScrollOption) == "1"));
|
||||||
Settings::setValue(Settings::Client::InvertScrollDirection, value);
|
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
|
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,12 @@ struct CoreArgs
|
||||||
"invertScrollDirection", "Client Mode: Set scroll direciton to be inverted (default: false)", "value"
|
"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,
|
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||||
portOption, nameOption, logLevelOption, logFileOption,
|
portOption, nameOption, logLevelOption, logFileOption,
|
||||||
secureOption, tlsCertOption, preventSleepOption, restartOption,
|
secureOption, tlsCertOption, preventSleepOption, restartOption,
|
||||||
displayOption, useHooksOption, peerCheckOption, serverConfigOption,
|
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();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,22 +164,12 @@ void ArgParserTests::assembleCommand()
|
||||||
void ArgParserTests::clientArgs()
|
void ArgParserTests::clientArgs()
|
||||||
{
|
{
|
||||||
deskflow::ClientArgs args;
|
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(m_parser.parseClientArgs(args, sizeof(argv) / sizeof(argv[0]), argv));
|
||||||
QVERIFY(args.m_shouldExitOk);
|
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()
|
void ArgParserTests::client_badArgs()
|
||||||
{
|
{
|
||||||
deskflow::ClientArgs clientArgs;
|
deskflow::ClientArgs clientArgs;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ private Q_SLOTS:
|
||||||
void getArgv();
|
void getArgv();
|
||||||
void assembleCommand();
|
void assembleCommand();
|
||||||
void clientArgs();
|
void clientArgs();
|
||||||
void client_setAddress();
|
|
||||||
void client_badArgs();
|
void client_badArgs();
|
||||||
void deprecatedArg_crypoPass_true();
|
void deprecatedArg_crypoPass_true();
|
||||||
void deprecatedArg_crypoPass_false();
|
void deprecatedArg_crypoPass_false();
|
||||||
|
|
|
||||||
|
|
@ -410,6 +410,16 @@ void CoreArgParserTests::client_invertScrolling_0()
|
||||||
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
|
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()
|
void CoreArgParserTests::preventSleep_true()
|
||||||
{
|
{
|
||||||
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ private Q_SLOTS:
|
||||||
void client_invertScrolling_false();
|
void client_invertScrolling_false();
|
||||||
void client_invertScrolling_1();
|
void client_invertScrolling_1();
|
||||||
void client_invertScrolling_0();
|
void client_invertScrolling_0();
|
||||||
|
void client_remoteHost();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue