1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

LibCore: Don't assume ArgsParser arguments are non-empty

This was fine before as the last entry was a null string (which could be
printed), but we no longer use C-style sentinel-terminated arrays for
arguments.
This commit is contained in:
Ali Mohammad Pur 2023-03-31 04:02:23 +03:30 committed by Andreas Kling
parent 1173adb90a
commit 83cb73a045

View file

@ -27,13 +27,20 @@ ArgsParser::ArgsParser()
bool ArgsParser::parse(Span<StringView> arguments, FailureBehavior failure_behavior)
{
auto fail = [this, name = arguments[0], failure_behavior] {
auto fail_impl = [this, failure_behavior](StringView name) {
if (failure_behavior == FailureBehavior::PrintUsage || failure_behavior == FailureBehavior::PrintUsageAndExit)
print_usage(stderr, name);
if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
exit(1);
};
if (arguments.is_empty()) {
fail_impl("<exe>"sv);
return false;
}
auto fail = [name = arguments[0], &fail_impl] { fail_impl(name); };
OptionParser parser;
Vector<OptionParser::Option> long_options;