feat: remove toml config file only use our QSettings based format
remove deskflow/Config and related tests
This commit is contained in:
committed by
Chris Rizzitello
parent
e30025ea8b
commit
4a5f173422
@ -38,26 +38,25 @@ runs:
|
||||
xorg-dev libx11-dev libxtst-dev libssl-dev \
|
||||
libglib2.0-dev libxkbfile-dev qt6-base-dev qt6-tools-dev \
|
||||
libgtk-3-dev libgtest-dev libgmock-dev \
|
||||
libei-dev libportal-dev libtomlplusplus-dev libcli11-dev \
|
||||
libei-dev libportal-dev libcli11-dev \
|
||||
help2man -y >/dev/null
|
||||
elif [ ${{inputs.like}} == "fedora" ]; then
|
||||
dnf install -y cmake make ninja-build gcc-c++ \
|
||||
rpm-build openssl-devel glib2-devel \
|
||||
libXtst-devel libxkbfile-devel qt6-qtbase-devel qt6-qttools-devel \
|
||||
gtk3-devel gtest-devel gmock-devel \
|
||||
libei-devel libportal-devel tomlplusplus-devel \
|
||||
cli11-devel help2man
|
||||
libei-devel libportal-devel cli11-devel help2man
|
||||
elif [ ${{inputs.like}} == "suse" ]; then
|
||||
zypper refresh
|
||||
zypper install -y --force-resolution \
|
||||
cmake make ninja gcc-c++ rpm-build libopenssl-devel \
|
||||
glib2-devel libXtst-devel libxkbfile-devel qt6-base-devel qt6-tools-devel gtk3-devel \
|
||||
googletest-devel googlemock-devel libei-devel \
|
||||
libportal-devel tomlplusplus-devel cli11-devel help2man
|
||||
libportal-devel cli11-devel help2man
|
||||
elif [ ${{ inputs.like }} == "arch" ]; then
|
||||
pacman -Syu --noconfirm base-devel cmake ninja \
|
||||
gcc openssl glib2 libxtst libxkbfile gtest libei libportal \
|
||||
qt6-base qt6-tools qt6-svg gtk3 tomlplusplus cli11 help2man doxygen graphviz rsync
|
||||
qt6-base qt6-tools qt6-svg gtk3 cli11 help2man doxygen graphviz rsync
|
||||
else
|
||||
echo "Unknown like"
|
||||
fi
|
||||
|
||||
@ -33,7 +33,6 @@ depends=(
|
||||
openssl
|
||||
qt6-base
|
||||
qt6-svg
|
||||
tomlplusplus
|
||||
)
|
||||
|
||||
options=('!debug')
|
||||
|
||||
@ -17,7 +17,6 @@ cleanup:
|
||||
- /lib/cmake
|
||||
- /lib/pkgconfig
|
||||
- /share/pkgconfig
|
||||
- /share/tomlplusplus
|
||||
- /share/cmake
|
||||
- /share/doc
|
||||
- /share/gir-1.0
|
||||
@ -72,13 +71,6 @@ modules:
|
||||
url: https://github.com/CLIUtils/CLI11
|
||||
tag: v2.5.0
|
||||
commit: 4160d259d961cd393fd8d67590a8c7d210207348
|
||||
- name: tomlplusplus
|
||||
buildsystem: cmake-ninja
|
||||
sources:
|
||||
- type: git
|
||||
url: https://github.com/marzer/tomlplusplus
|
||||
tag: v3.4.0
|
||||
commit: 30172438cee64926dc41fdd9c11fb3ba5b2ba9de
|
||||
- name: gtest
|
||||
buildsystem: cmake-ninja
|
||||
sources:
|
||||
|
||||
@ -7,7 +7,6 @@ To build Deskflow you will a minimum of:
|
||||
- [libportal] 0.8+ (linux, bsd)
|
||||
- [libei] 1.3+ (linux, bsd)
|
||||
- [google_test] ^
|
||||
- [tomlplusplus] ^
|
||||
- [cli11] ^
|
||||
|
||||
> ^ Will be fetched if not found on the host system.
|
||||
@ -76,7 +75,6 @@ After configuring you should be able to run make to build all targets.
|
||||
[cmake]:https://cmake.org/
|
||||
[openssl]:https://www.openssl.org/
|
||||
[google_test]:https://github.com/google/googletest
|
||||
[tomlplusplus]:https://github.com/marzer/tomlplusplus
|
||||
[cli11]:https://github.com/CLIUtils/CLI11
|
||||
[libei]:https://gitlab.freedesktop.org/libinput/libei
|
||||
[libportal]:https://github.com/flatpak/libportal
|
||||
|
||||
@ -803,25 +803,6 @@ section: links
|
||||
end
|
||||
```
|
||||
|
||||
# Example file for `--config-toml` arg
|
||||
|
||||
```
|
||||
[server.args]
|
||||
no-daemon = true
|
||||
no-tray = true
|
||||
debug = "DEBUG"
|
||||
name = "moe"
|
||||
address = ":24800"
|
||||
|
||||
[client.args]
|
||||
no-daemon = true
|
||||
no-tray = true
|
||||
debug = "DEBUG2"
|
||||
name = "larry"
|
||||
_last = "moe:24800"
|
||||
```
|
||||
|
||||
|
||||
# Example `.env` file
|
||||
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
#include "common/Constants.h"
|
||||
#include "common/ExitCodes.h"
|
||||
#include "common/Settings.h"
|
||||
#include "deskflow/Config.h"
|
||||
#include "deskflow/DeskflowException.h"
|
||||
#include "deskflow/ProtocolTypes.h"
|
||||
|
||||
@ -143,9 +142,7 @@ void App::loggingFilterWarning() const
|
||||
|
||||
void App::initApp(int argc, const char **argv)
|
||||
{
|
||||
std::string configFilename;
|
||||
CLI::App cliApp{kAppDescription};
|
||||
cliApp.add_option("--config-toml", configFilename, "Use TOML configuration file");
|
||||
|
||||
// Allow legacy args.
|
||||
cliApp.allow_extras();
|
||||
@ -157,14 +154,7 @@ void App::initApp(int argc, const char **argv)
|
||||
cliApp.exit(e);
|
||||
}
|
||||
|
||||
if (!configFilename.empty()) {
|
||||
Config config(configFilename, configSection());
|
||||
if (config.load(argv[0])) {
|
||||
parseArgs();
|
||||
}
|
||||
} else {
|
||||
parseArgs();
|
||||
}
|
||||
parseArgs();
|
||||
|
||||
// set log filter
|
||||
if (const auto logLevel = qPrintable(Settings::logLevelText()); !CLOG->setFilter(logLevel)) {
|
||||
|
||||
@ -21,26 +21,6 @@ else()
|
||||
message(STATUS "CLI11 INC_DIR: ${cli11_inc_dir}")
|
||||
endif()
|
||||
|
||||
find_package(tomlplusplus QUIET)
|
||||
if(tomlplusplus_FOUND)
|
||||
message(STATUS "tomlplusplus [System] Version: ${tomlplusplus_VERSION}")
|
||||
set(tomlPP_lib tomlplusplus::tomlplusplus)
|
||||
else()
|
||||
# Be sure to update the version and MD5 together
|
||||
# Save our copy with .h not .hpp for compatibliy with system version < 3.4
|
||||
set(TOMLPP_VERSION 3.4.0)
|
||||
set(TOMLPP_MD5 caefb3b60119731fb4b4d24b6339e7fb)
|
||||
file(
|
||||
DOWNLOAD "https://raw.githubusercontent.com/marzer/tomlplusplus/refs/tags/v${TOMLPP_VERSION}/toml.hpp"
|
||||
"${CMAKE_BINARY_DIR}/include/toml++/toml.h"
|
||||
SHOW_PROGRESS
|
||||
EXPECTED_MD5 ${TOMLPP_MD5}
|
||||
)
|
||||
set(tomlPP_inc_dir "${CMAKE_BINARY_DIR}/include")
|
||||
message(STATUS "tomlplusplus [Downloaded] Version: 3.4.0")
|
||||
message(STATUS "tomlplusplus INC DIR: ${tomlPP_inc_dir}")
|
||||
endif()
|
||||
|
||||
####################Start Making Library#########################
|
||||
set(lib_name app)
|
||||
|
||||
@ -76,8 +56,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
||||
Clipboard.h
|
||||
ClipboardChunk.cpp
|
||||
ClipboardChunk.h
|
||||
Config.cpp
|
||||
Config.h
|
||||
CoreArgParser.cpp
|
||||
CoreArgParser.h
|
||||
CoreArgs.h
|
||||
@ -132,14 +110,13 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE}
|
||||
target_link_libraries(${lib_name} PUBLIC common Qt6::Core Qt6::Network)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${lib_name} PRIVATE ${cli11_lib} ${tomlPP_lib})
|
||||
target_link_libraries(${lib_name} PRIVATE ${cli11_lib})
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
${lib_name}
|
||||
PRIVATE
|
||||
${cli11_inc_dir}
|
||||
${tomlPP_inc_dir}
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
@ -154,7 +131,6 @@ if(UNIX)
|
||||
mt
|
||||
server
|
||||
${cli11_lib}
|
||||
${tomlPP_lib}
|
||||
)
|
||||
|
||||
if(NOT APPLE)
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "base/Log.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Use .h for fallback with 3.3.0
|
||||
#include <toml++/toml.h>
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
Config::Config(const std::string &filename, const std::string §ion) : m_filename(filename), m_section(section)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const char *const *Config::argv() const
|
||||
{
|
||||
return m_argv.data();
|
||||
}
|
||||
|
||||
int Config::argc() const
|
||||
{
|
||||
return static_cast<int>(m_argv.size());
|
||||
}
|
||||
|
||||
bool Config::load(const std::string &firstArg)
|
||||
{
|
||||
|
||||
if (!firstArg.empty()) {
|
||||
m_args.push_back(firstArg);
|
||||
}
|
||||
|
||||
if (m_filename.empty()) {
|
||||
throw NoConfigFilenameError();
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(m_filename)) {
|
||||
LOG_ERR("config file not found: %s", m_filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
toml::table configTable;
|
||||
try {
|
||||
LOG_INFO("loading config file: %s", m_filename.c_str());
|
||||
configTable = toml::parse_file(m_filename);
|
||||
|
||||
} catch (const toml::parse_error &err) {
|
||||
LOG_ERR("toml parse error: %s", err.what());
|
||||
throw ParseError();
|
||||
} catch (const std::exception &err) {
|
||||
LOG_ERR("unknown parse error: %s", err.what());
|
||||
throw ParseError();
|
||||
}
|
||||
|
||||
if (!configTable.contains(m_section)) {
|
||||
LOG_WARN("no %s section found in config file", m_section.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto §ion = configTable[m_section];
|
||||
const auto args = section["args"];
|
||||
if (!args.is_table()) {
|
||||
LOG_WARN("no args table found in config file");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string specialLastArg = "";
|
||||
const auto &table = *(args.as_table());
|
||||
for (const auto &pair : table) {
|
||||
const auto &key = pair.first;
|
||||
if (key.str() == "_last") {
|
||||
specialLastArg = pair.second.as_string()->get();
|
||||
continue;
|
||||
}
|
||||
|
||||
m_args.push_back("--" + std::string(key.str()));
|
||||
|
||||
if (pair.second.is_string()) {
|
||||
const auto value = pair.second.as_string()->get();
|
||||
m_args.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!specialLastArg.empty()) {
|
||||
m_args.push_back(specialLastArg);
|
||||
}
|
||||
|
||||
if (m_args.empty()) {
|
||||
LOG_WARN("no args loaded from config file");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &arg : m_args) {
|
||||
m_argv.push_back(arg.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace deskflow
|
||||
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
//! App configuration
|
||||
/*!
|
||||
Parses a configuration file describing start args and potentially other
|
||||
configuration options in future. The configuration file is in TOML format.
|
||||
|
||||
Initially this class was created to as a developer convenience; it is a
|
||||
convenient place to specify args without needing to fiddle with IDE configs.
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
class ParseError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit ParseError() : std::runtime_error("failed to parse config file")
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
class NoConfigFilenameError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit NoConfigFilenameError() : std::runtime_error("no config file specified")
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
};
|
||||
|
||||
explicit Config(const std::string &filename, const std::string §ion);
|
||||
|
||||
bool load(const std::string &firstArg);
|
||||
const char *const *argv() const;
|
||||
int argc() const;
|
||||
|
||||
private:
|
||||
std::string m_filename;
|
||||
std::string m_section;
|
||||
std::vector<std::string> m_args;
|
||||
std::vector<const char *> m_argv;
|
||||
};
|
||||
|
||||
} // namespace deskflow
|
||||
@ -29,14 +29,6 @@ create_test(
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME ConfigTests
|
||||
DEPENDS app
|
||||
LIBS arch base ${extra_libs}
|
||||
SOURCE ConfigTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/deskflow"
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME IKeyStateTests
|
||||
DEPENDS app
|
||||
|
||||
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "ConfigTests.h"
|
||||
|
||||
#include "deskflow/Config.h"
|
||||
|
||||
using namespace deskflow;
|
||||
const auto kTestFilename = "tmp/test/test.toml";
|
||||
|
||||
void ConfigTests::initTestCase()
|
||||
{
|
||||
QDir dir;
|
||||
QVERIFY(dir.mkpath("tmp/test"));
|
||||
|
||||
m_arch.init();
|
||||
m_log.setFilter(LogLevel::Debug2);
|
||||
}
|
||||
|
||||
void ConfigTests::loadFile()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Text));
|
||||
|
||||
QTextStream out(&testFile);
|
||||
out << "[test.args]\n"
|
||||
R"(test-arg = "test opt")";
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
Config config(kTestFilename, "test");
|
||||
|
||||
const auto result = config.load("test");
|
||||
QVERIFY(result);
|
||||
QCOMPARE(config.argc(), 3);
|
||||
QCOMPARE(config.argv()[0], "test");
|
||||
QCOMPARE(config.argv()[1], "--test-arg");
|
||||
QCOMPARE(config.argv()[2], "test opt");
|
||||
}
|
||||
|
||||
void ConfigTests::load_EmptyFile()
|
||||
{
|
||||
Config config("", "test");
|
||||
QVERIFY_THROWS_EXCEPTION(Config::NoConfigFilenameError, config.load("test"));
|
||||
}
|
||||
|
||||
void ConfigTests::load_NonExsitingFile()
|
||||
{
|
||||
Config config("nonexistent.toml", "test");
|
||||
|
||||
const auto result = config.load("test");
|
||||
QVERIFY(!result);
|
||||
}
|
||||
|
||||
void ConfigTests::load_InvalidConfig()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
||||
|
||||
QVERIFY(testFile.write("foobar"));
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
Config config(kTestFilename, "test");
|
||||
QVERIFY_THROWS_EXCEPTION(Config::ParseError, config.load("test"));
|
||||
}
|
||||
|
||||
void ConfigTests::load_missingSections()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
Config config(kTestFilename, "missing");
|
||||
const auto result = config.load("test");
|
||||
QVERIFY(!result);
|
||||
}
|
||||
|
||||
void ConfigTests::load_badTable()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
||||
|
||||
QVERIFY(testFile.write("[test]"));
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
Config config(kTestFilename, "test");
|
||||
|
||||
const auto result = config.load("test");
|
||||
QVERIFY(!result);
|
||||
}
|
||||
|
||||
void ConfigTests::load_lastArg()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
||||
|
||||
QVERIFY(testFile.write(
|
||||
"[test.args]\n"
|
||||
R"(_last = "test last")"
|
||||
"\n"
|
||||
R"(test-second = true)"
|
||||
));
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
deskflow::Config config(kTestFilename, "test");
|
||||
|
||||
const auto result = config.load("test-first");
|
||||
QVERIFY(result);
|
||||
QCOMPARE(config.argc(), 3);
|
||||
QCOMPARE(config.argv()[0], "test-first");
|
||||
QCOMPARE(config.argv()[1], "--test-second");
|
||||
QCOMPARE(config.argv()[2], "test last");
|
||||
}
|
||||
|
||||
void ConfigTests::load_noArgs()
|
||||
{
|
||||
QFile testFile(kTestFilename);
|
||||
QVERIFY(testFile.open(QIODevice::WriteOnly));
|
||||
|
||||
QVERIFY(testFile.write("[test.args]"));
|
||||
|
||||
testFile.close();
|
||||
QVERIFY(!testFile.isOpen());
|
||||
|
||||
deskflow::Config config(kTestFilename, "test");
|
||||
|
||||
const auto result = config.load("");
|
||||
QVERIFY(!result);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ConfigTests)
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "base/Log.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class ConfigTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
// Test are run in order top to bottom
|
||||
void initTestCase();
|
||||
void loadFile();
|
||||
void load_EmptyFile();
|
||||
void load_NonExsitingFile();
|
||||
void load_InvalidConfig();
|
||||
void load_missingSections();
|
||||
void load_badTable();
|
||||
void load_lastArg();
|
||||
void load_noArgs();
|
||||
|
||||
private:
|
||||
Arch m_arch;
|
||||
Log m_log;
|
||||
};
|
||||
Reference in New Issue
Block a user