diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-09-22 14:34:00 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-09-25 13:32:30 +0200 |
commit | 0227635315c3aa1c31e6814325822a1e4306372e (patch) | |
tree | c44ead0ca5f44ec7b17a8f9830da63bce06d3d00 /src/node_options-inl.h | |
parent | 5605cec0db9481d4cc85da1a7869f1d725c4357f (diff) | |
download | android-node-v8-0227635315c3aa1c31e6814325822a1e4306372e.tar.gz android-node-v8-0227635315c3aa1c31e6814325822a1e4306372e.tar.bz2 android-node-v8-0227635315c3aa1c31e6814325822a1e4306372e.zip |
cli: normalize `_` → `-` when parsing options
This allows for option syntax similar to V8’s one, e.g.
`--no_warnings` has the same effect as `--no-warnings`.
PR-URL: https://github.com/nodejs/node/pull/23020
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'src/node_options-inl.h')
-rw-r--r-- | src/node_options-inl.h | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 1d1eda5475..277121036e 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -307,6 +307,12 @@ void OptionsParser<Options>::Parse( if (equals_index != std::string::npos) original_name += '='; + // Normalize by replacing `_` with `-` in options. + for (std::string::size_type i = 2; i < name.size(); ++i) { + if (name[i] == '_') + name[i] = '-'; + } + { auto it = aliases_.end(); // Expand aliases: @@ -341,19 +347,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) { |