Skip to content

Commit

Permalink
config: add -c, --config commandline options
Browse files Browse the repository at this point in the history
  • Loading branch information
bvr-yr committed Mar 17, 2024
1 parent 2ae7975 commit 44c45f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = true}) {
configCurrentPath = configPath.empty() ? getMainConfigPath() : configPath;
}

void CConfigManager::init() {
Expand Down
2 changes: 1 addition & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CConfigManager {
public:
CConfigManager();
CConfigManager(std::string configPath);
void init();
void* const* getValuePtr(const std::string& name);

Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
configPath = argv[++i];

else if (arg == "--display" && i + 1 < argc) {
wlDisplay = argv[i + 1];
i++;
Expand All @@ -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);
Expand Down

0 comments on commit 44c45f3

Please sign in to comment.