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
This commit is contained in:
Eduard Tykhoniuk 2024-09-25 11:41:09 +02:00 committed by GitHub
parent 22b058b47a
commit cc23f97836
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,7 +16,21 @@ int main(int argc, char** argv, char** envp) {
Debug::quiet = true; Debug::quiet = true;
else if (arg == "--config" || arg == "-c") { 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]; 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;
}
} }
} }