-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: normalize _
→ -
when parsing options
#23020
Changes from 2 commits
671173e
841cf93
a389c08
7ca87b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,13 @@ void OptionsParser<Options>::Parse( | |
if (equals_index != std::string::npos) | ||
original_name += '='; | ||
|
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO should be:
So there's no need for the scope, and no use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still have as a rule here to avoid using non-const references., and the rule you linked doesn’t seem to apply here (this is not a for loop to begin with). If you want, this can be for (std::string::size_type i = 0; i < name.size(); ++i) {
if (name[i] == '_')
name[i] = '-';
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P.S. There ES.72 - Prefer a for-statement to a while-statement when there is an obvious loop variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The one you suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have no doubt rules have good reasons. Personally I'm assuming anything that is not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Where can I find a reference to that? |
||
// Normalize by replacing `_` with `-` in options. | ||
std::string::size_type index = 2; // Start after initial '--'. | ||
while ((index = name.find('_', index + 1)) != std::string::npos) | ||
name[index] = '-'; | ||
} | ||
|
||
{ | ||
auto it = aliases_.end(); | ||
// Expand aliases: | ||
|
@@ -341,19 +348,6 @@ void OptionsParser<Options>::Parse( | |
|
||
auto it = options_.find(name); | ||
|
||
if (it == options_.end()) { | ||
// We would assume that this is a V8 option if neither we nor any child | ||
// parser knows about it, so we convert - to _ for | ||
// canonicalization (since V8 accepts both) and look up again in order | ||
// to find a match. | ||
// TODO(addaleax): Make the canonicalization unconditional, i.e. allow | ||
// both - and _ in Node's own options as well. | ||
std::string::size_type index = 2; // Start after initial '--'. | ||
while ((index = name.find('-', index + 1)) != std::string::npos) | ||
name[index] = '_'; | ||
it = options_.find(name); | ||
} | ||
|
||
if ((it == options_.end() || | ||
it->second.env_setting == kDisallowedInEnvironment) && | ||
required_env_settings == kAllowedInEnvironment) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REPLACEME -> 23020?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, done!