config: add -c, --config commandline options (#202)

* config: add -c, --config commandline options

* argc

* don't allow missing custom config file
This commit is contained in:
bvr-yr 2024-03-18 18:04:39 +03:00 committed by GitHub
parent 2ae79757d5
commit 1356f113cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 4 deletions

View file

@ -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() {

View file

@ -10,7 +10,7 @@
class CConfigManager {
public:
CConfigManager();
CConfigManager(std::string configPath);
void init();
void* const* getValuePtr(const std::string& name);

View file

@ -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<CConfigManager>();
g_pConfigManager = std::make_unique<CConfigManager>(configPath);
g_pConfigManager->init();
} catch (const char* err) {
Debug::log(CRIT, "ConfigManager threw: {}", err);