config: Add a -c|--config flag to set a config path (#25)

This commit is contained in:
Anthony Ruhier 2024-02-29 17:19:33 +01:00 committed by GitHub
parent cc465d04d6
commit 029f08805a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 4 deletions

View file

@ -48,3 +48,12 @@ Installation:
```sh ```sh
sudo cmake --install build sudo cmake --install build
``` ```
## Flags
```
-c <config_path>, --config <config_path>: specify a config path, by default
set to ${XDG_CONFIG_HOME}/hypr/hypridle.conf
-q, --quiet
-v, --verbose
```

View file

@ -14,7 +14,7 @@ static std::string getMainConfigPath() {
return getConfigDir() + "/hypr/hypridle.conf"; return getConfigDir() + "/hypr/hypridle.conf";
} }
CConfigManager::CConfigManager() : m_config(getMainConfigPath().c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = false}) { CConfigManager::CConfigManager(std::string configPath) : m_config(configPath.empty() ? getMainConfigPath().c_str() : configPath.c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = false}) {
; ;
} }

View file

@ -9,7 +9,7 @@
class CConfigManager { class CConfigManager {
public: public:
CConfigManager(); CConfigManager(std::string configPath);
void init(); void init();
struct STimeoutRule { struct STimeoutRule {

View file

@ -3,6 +3,7 @@
#include "core/Hypridle.hpp" #include "core/Hypridle.hpp"
int main(int argc, char** argv, char** envp) { int main(int argc, char** argv, char** envp) {
std::string configPath;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
std::string arg = argv[i]; std::string arg = argv[i];
@ -12,10 +13,14 @@ int main(int argc, char** argv, char** envp) {
else if (arg == "--quiet" || arg == "-q") else if (arg == "--quiet" || arg == "-q")
Debug::quiet = true; Debug::quiet = true;
else if (arg == "--config" || arg == "-c") {
configPath = argv[++i];
}
} }
try { try {
g_pConfigManager = std::make_unique<CConfigManager>(); g_pConfigManager = std::make_unique<CConfigManager>(configPath);
g_pConfigManager->init(); g_pConfigManager->init();
} catch (const char* err) { } catch (const char* err) {
Debug::log(CRIT, "ConfigManager threw: {}", err); Debug::log(CRIT, "ConfigManager threw: {}", err);