From 1356f113cce5e87e7e8409a9c45d3bf8fa36f39d Mon Sep 17 00:00:00 2001 From: bvr-yr <130279855+bvr-yr@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:04:39 +0300 Subject: [PATCH] config: add -c, --config commandline options (#202) * config: add -c, --config commandline options * argc * don't allow missing custom config file --- src/config/ConfigManager.cpp | 4 ++-- src/config/ConfigManager.hpp | 2 +- src/main.cpp | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index a90b7b7..89f731a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -30,8 +30,8 @@ static std::string getMainConfigPath() { return getConfigDir() + "/hypr/hyprlock.conf"; } -CConfigManager::CConfigManager() : m_config(getMainConfigPath().c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = true}) { - configCurrentPath = getMainConfigPath(); +CConfigManager::CConfigManager(std::string configPath) : m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = configPath.empty()}) { + configCurrentPath = configPath.empty() ? getMainConfigPath() : configPath; } void CConfigManager::init() { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index d1b5d87..8b2f373 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -10,7 +10,7 @@ class CConfigManager { public: - CConfigManager(); + CConfigManager(std::string configPath); void init(); void* const* getValuePtr(const std::string& name); diff --git a/src/main.cpp b/src/main.cpp index 094c946..cf47ac0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,11 +7,13 @@ void help() { "Options:\n" " -v, --verbose - Enable verbose logging\n" " -q, --quiet - Disable logging\n" + " -c FILE, --config FILE - Specify config file to use\n" " --display (display) - Specify the Wayland display to connect to\n" " --immediate - Lock immediately, ignoring any configured grace period\n" " -h, --help - Show this help message\n"; } int main(int argc, char** argv, char** envp) { + std::string configPath; std::string wlDisplay; bool immediate = false; @@ -24,6 +26,9 @@ int main(int argc, char** argv, char** envp) { else if (arg == "--quiet" || arg == "-q") Debug::quiet = true; + else if ((arg == "--config" || arg == "-c") && i + 1 < argc) + configPath = argv[++i]; + else if (arg == "--display" && i + 1 < argc) { wlDisplay = argv[i + 1]; i++; @@ -37,7 +42,7 @@ int main(int argc, char** argv, char** envp) { } try { - g_pConfigManager = std::make_unique(); + g_pConfigManager = std::make_unique(configPath); g_pConfigManager->init(); } catch (const char* err) { Debug::log(CRIT, "ConfigManager threw: {}", err);