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
1 changed files with 10 additions and 14 deletions

View File

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