From 5e8f12c2d9f9b8ff3c67ecbed39da07ba95a810c Mon Sep 17 00:00:00 2001 From: davc0n Date: Sun, 28 Jul 2024 20:10:36 +0200 Subject: [PATCH] core: minor refactor of command line options parsing (#441) --- src/main.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a5270ad..fda4f2e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 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(configPath); g_pConfigManager->init();