mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +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:
parent
1173adb90a
commit
83cb73a045
1 changed files with 8 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue