From cc23f97836adbba1abc8edd48169fb1f1f698c32 Mon Sep 17 00:00:00 2001 From: Eduard Tykhoniuk <50710486+MAKMED1337@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:41:09 +0200 Subject: [PATCH] core: Do not crash if the last CLI parameter was -c (#92) * fix: Do not crash if the last CLI parameter was -c * feat: return an error if the next argument after -c is a flag * feat: return an error if multiple config files are provided --- src/main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index c1874ac..71dbd1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,21 @@ int main(int argc, char** argv, char** envp) { Debug::quiet = true; else if (arg == "--config" || arg == "-c") { + if (i + 1 >= argc) { + Debug::log(NONE, "After " + arg + " you should provide a path to a config file."); + return 1; + } + + if (!configPath.empty()) { + Debug::log(NONE, "Multiple config files are provided."); + return 1; + } + configPath = argv[++i]; + if (configPath[0] == '-') { // Should be fine, because of the null terminator + Debug::log(NONE, "After " + arg + " you should provide a path to a config file."); + return 1; + } } }