core: minor refactor of command line options parsing (#441)

This commit is contained in:
davc0n 2024-07-28 20:10:36 +02:00 committed by GitHub
parent cf0e975fed
commit 5e8f12c2d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,9 +11,10 @@ void help() {
" -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"
" --display NAME - Specify the Wayland display to connect to\n"
" --immediate - Lock immediately, ignoring any configured grace period\n"
" --immediate-render - Do not wait for resources before drawing the background\n"
" -V, --version - Show version information\n"
" -h, --help - Show this help message\n";
}
@ -31,21 +32,25 @@ int main(int argc, char** argv, char** envp) {
std::string wlDisplay;
bool immediate = false;
bool immediateRender = false;
bool showHelp = false;
std::vector<std::string> args(argv, argv + argc);
for (std::size_t i = 1; i < args.size(); ++i) {
const std::string arg = argv[i];
if (arg == "--verbose" || arg == "-v")
Debug::verbose = true;
if (arg == "--help" || arg == "-h") {
help();
return 0;
}
if (arg == "--version" || arg == "-V") {
std::cout << "Hyprlock version " << HYPRLOCK_VERSION << "\n";
return 0;
}
if (arg == "--verbose" || arg == "-v")
Debug::verbose = true;
else if (arg == "--quiet" || arg == "-q")
Debug::quiet = true;
@ -67,22 +72,13 @@ int main(int argc, char** argv, char** envp) {
else if (arg == "--immediate-render")
immediateRender = true;
else if (arg == "--help" || arg == "-h") {
showHelp = true;
break;
} else {
else {
std::cerr << "Unknown option: " << arg << "\n";
help();
return 1;
}
}
if (showHelp) {
help();
return 0;
}
try {
g_pConfigManager = std::make_unique<CConfigManager>(configPath);
g_pConfigManager->init();