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

@ -13,7 +13,7 @@ hyprland syntax.
```ini
general {
lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session)
lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session)
unlock_cmd = notify-send "unlock!" # same as above, but unlock
before_sleep_cmd = notify-send "Zzz" # command ran before sleep
after_sleep_cmd = notify-send "Awake!" # command ran after sleep
@ -48,3 +48,12 @@ Installation:
```sh
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";
}
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 {
public:
CConfigManager();
CConfigManager(std::string configPath);
void init();
struct STimeoutRule {

View file

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