refactor: move -c --config to coreArgs
This commit is contained in:
committed by
Chris Rizzitello
parent
cfedfc2c1e
commit
bf7a50ab0e
@ -25,32 +25,6 @@ ArgParser::ArgParser(App *app) : m_app(app)
|
||||
{
|
||||
}
|
||||
|
||||
bool ArgParser::parseServerArgs(deskflow::ServerArgs &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, "server")) {
|
||||
++i;
|
||||
continue;
|
||||
} else if (isArg(i, argc, argv, "-c", "--config", 1)) {
|
||||
// save configuration file path
|
||||
args.m_configFile = argv[++i];
|
||||
} else {
|
||||
LOG_CRIT("%s: unrecognized option `%s'" BYE, "deskflow-core", argv[i], "deskflow-core");
|
||||
return false;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (checkUnexpectedArgs()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv) const
|
||||
{
|
||||
setArgsBase(args);
|
||||
|
||||
@ -23,7 +23,6 @@ class ArgParser
|
||||
public:
|
||||
explicit ArgParser(App *app);
|
||||
|
||||
bool parseServerArgs(deskflow::ServerArgs &args, int argc, const char *const *argv) const;
|
||||
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;
|
||||
|
||||
@ -116,6 +116,10 @@ void CoreArgParser::parse()
|
||||
(m_parser.value(CoreArgs::peerCheckOption) == "1"));
|
||||
Settings::setValue(Settings::Security::CheckPeers, value);
|
||||
}
|
||||
|
||||
if (m_parser.isSet(CoreArgs::serverConfigOption)) {
|
||||
Settings::setValue(Settings::Server::ExternalConfigFile, m_parser.value(CoreArgs::serverConfigOption));
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void CoreArgParser::showHelpText() const
|
||||
|
||||
@ -63,8 +63,11 @@ struct CoreArgs
|
||||
"peerCertCheck", "Server Mode: Enable client SSL certificate checking (default: true)", "value"
|
||||
);
|
||||
|
||||
inline static const auto serverConfigOption =
|
||||
QCommandLineOption("serverConfig", "Server Mode: File to load as server config", "path");
|
||||
|
||||
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
|
||||
portOption, nameOption, logLevelOption, logFileOption,
|
||||
secureOption, tlsCertOption, preventSleepOption, restartOption,
|
||||
displayOption, useHooksOption, peerCheckOption};
|
||||
displayOption, useHooksOption, peerCheckOption, serverConfigOption};
|
||||
};
|
||||
|
||||
@ -78,39 +78,20 @@ ServerApp::ServerApp(IEventQueue *events, const QString &processName)
|
||||
|
||||
void ServerApp::parseArgs(int argc, const char *const *argv)
|
||||
{
|
||||
|
||||
ArgParser argParser(this);
|
||||
bool result = argParser.parseServerArgs(args(), argc, argv);
|
||||
|
||||
if (!result || args().m_shouldExitOk || args().m_shouldExitFail) {
|
||||
if (args().m_shouldExitOk) {
|
||||
bye(s_exitSuccess);
|
||||
} else {
|
||||
if (const auto address = Settings::value(Settings::Core::Interface).toString(); !address.isEmpty()) {
|
||||
try {
|
||||
*m_deskflowAddress = NetworkAddress(address.toStdString(), kDefaultPort);
|
||||
m_deskflowAddress->resolve();
|
||||
} catch (SocketAddressException &e) {
|
||||
LOG_CRIT("%s: %s" BYE, qPrintable(processName()), e.what(), qPrintable(processName()));
|
||||
bye(s_exitArgs);
|
||||
}
|
||||
} else {
|
||||
if (const auto address = Settings::value(Settings::Core::Interface).toString(); !address.isEmpty()) {
|
||||
try {
|
||||
*m_deskflowAddress = NetworkAddress(address.toStdString(), kDefaultPort);
|
||||
m_deskflowAddress->resolve();
|
||||
} catch (SocketAddressException &e) {
|
||||
LOG_CRIT("%s: %s" BYE, qPrintable(processName()), e.what(), qPrintable(processName()));
|
||||
bye(s_exitArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerApp::help()
|
||||
{
|
||||
std::stringstream help;
|
||||
help << "\n\nServer Mode:\n\n"
|
||||
<< "Usage: " << kAppId << "-core server \n"
|
||||
<< " -c, --config <pathname> path of the configuration file\n"
|
||||
<< s_helpVersionArgs << "\n"
|
||||
<< s_helpNoWayland;
|
||||
|
||||
LOG_PRINT("%s", help.str().c_str());
|
||||
// do-nothing
|
||||
}
|
||||
|
||||
void ServerApp::reloadSignalHandler(Arch::ThreadSignal, void *)
|
||||
@ -122,7 +103,7 @@ void ServerApp::reloadSignalHandler(Arch::ThreadSignal, void *)
|
||||
void ServerApp::reloadConfig()
|
||||
{
|
||||
LOG_DEBUG("reload configuration");
|
||||
if (loadConfig(args().m_configFile)) {
|
||||
if (loadConfig(Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString())) {
|
||||
if (m_server != nullptr) {
|
||||
m_server->setConfig(*args().m_config);
|
||||
}
|
||||
@ -132,7 +113,7 @@ void ServerApp::reloadConfig()
|
||||
|
||||
void ServerApp::loadConfig()
|
||||
{
|
||||
const auto path = args().m_configFile;
|
||||
const auto path = Settings::value(Settings::Server::ExternalConfigFile).toString().toStdString();
|
||||
if (path.empty()) {
|
||||
LOG_CRIT("no configuration path provided");
|
||||
bye(s_exitConfig);
|
||||
|
||||
@ -27,7 +27,6 @@ public:
|
||||
ServerArgs &operator=(ServerArgs &&) = default;
|
||||
|
||||
public:
|
||||
std::string m_configFile = "";
|
||||
std::shared_ptr<Config> m_config;
|
||||
};
|
||||
|
||||
|
||||
@ -465,7 +465,6 @@ bool CoreProcess::addServerArgs(QStringList &args)
|
||||
return false;
|
||||
}
|
||||
|
||||
args << "-c" << configFilename;
|
||||
qInfo("core config file: %s", qPrintable(configFilename));
|
||||
// bizarrely, the tls cert path arg was being given to the core client.
|
||||
// since it's not clear why (it is only needed for the server), this has now
|
||||
|
||||
@ -162,26 +162,6 @@ void ArgParserTests::assembleCommand()
|
||||
QCOMPARE(command, "\"stub1 space\" stub2 \"stub3 space\"");
|
||||
}
|
||||
|
||||
void ArgParserTests::server_setConfigFile()
|
||||
{
|
||||
deskflow::ServerArgs serverArgs;
|
||||
const int argc = 3;
|
||||
const char *kConfigCmd[argc] = {"stub", "--config", "mock_configFile"};
|
||||
|
||||
m_parser.parseServerArgs(serverArgs, argc, kConfigCmd);
|
||||
|
||||
QCOMPARE(serverArgs.m_configFile, "mock_configFile");
|
||||
}
|
||||
|
||||
void ArgParserTests::serverArgs()
|
||||
{
|
||||
deskflow::ServerArgs args;
|
||||
char const *argv[] = {"deskflow", "--help", "--res-w", "888"};
|
||||
|
||||
QVERIFY(m_parser.parseServerArgs(args, sizeof(argv) / sizeof(argv[0]), argv));
|
||||
QVERIFY(args.m_shouldExitOk);
|
||||
}
|
||||
|
||||
void ArgParserTests::clientArgs()
|
||||
{
|
||||
deskflow::ClientArgs args;
|
||||
|
||||
@ -21,8 +21,6 @@ private Q_SLOTS:
|
||||
void splitCommand();
|
||||
void getArgv();
|
||||
void assembleCommand();
|
||||
void serverArgs();
|
||||
void server_setConfigFile();
|
||||
void clientArgs();
|
||||
void client_yScroll();
|
||||
void client_setLangSync();
|
||||
|
||||
@ -310,6 +310,16 @@ void CoreArgParserTests::server_peerCheck_true()
|
||||
QVERIFY(Settings::value(Settings::Security::CheckPeers).toBool());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::server_setConfig()
|
||||
{
|
||||
QStringList args = {"stub", "server", "--serverConfig", "afile.conf"};
|
||||
|
||||
CoreArgParser parser(args);
|
||||
parser.parse();
|
||||
|
||||
QCOMPARE("afile.conf", Settings::value(Settings::Server::ExternalConfigFile).toString());
|
||||
}
|
||||
|
||||
void CoreArgParserTests::preventSleep_true()
|
||||
{
|
||||
QStringList args = {"stub", "client", "--prevent-sleep", "true"};
|
||||
|
||||
@ -44,6 +44,7 @@ private Q_SLOTS:
|
||||
void hookOptions_true();
|
||||
void server_peerCheck_false();
|
||||
void server_peerCheck_true();
|
||||
void server_setConfig();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
|
||||
Reference in New Issue
Block a user