Skip to content

Commit

Permalink
src: replace goto with lambda in options parser
Browse files Browse the repository at this point in the history
PR-URL: #32635
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
tniessen authored and BethGriggs committed Apr 7, 2020
1 parent cbc254e commit 57856bc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos)
original_name += '=';

auto missing_argument = [&]() {
errors->push_back(RequiresArgumentErr(original_name));
};

// Normalize by replacing `_` with `-` in options.
for (std::string::size_type i = 2; i < name.size(); ++i) {
if (name[i] == '_')
Expand Down Expand Up @@ -381,18 +385,20 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos) {
value = arg.substr(equals_index + 1);
if (value.empty()) {
missing_argument:
errors->push_back(RequiresArgumentErr(original_name));
missing_argument();
break;
}
} else {
if (args.empty())
goto missing_argument;
if (args.empty()) {
missing_argument();
break;
}

value = args.pop_first();

if (!value.empty() && value[0] == '-') {
goto missing_argument;
missing_argument();
break;
} else {
if (!value.empty() && value[0] == '\\' && value[1] == '-')
value = value.substr(1); // Treat \- as escaping an -.
Expand Down

0 comments on commit 57856bc

Please sign in to comment.