From 671173e69473bdca3d84bcab619d6053989a08fe Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 14:34:00 +0200 Subject: [PATCH 1/4] =?UTF-8?q?cli:=20normalize=20`=5F`=20=E2=86=92=20`-`?= =?UTF-8?q?=20when=20parsing=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows for option syntax similar to V8’s one, e.g. `--no_warnings` has the same effect as `--no-warnings`. --- doc/api/cli.md | 17 +++++--- lib/internal/bootstrap/node.js | 42 +++++-------------- src/node_options-inl.h | 20 ++++----- src/node_options.cc | 12 +++--- .../test-cli-node-options-disallowed.js | 1 - test/parallel/test-cli-node-options.js | 1 + test/parallel/test-pending-deprecation.js | 8 ++++ 7 files changed, 43 insertions(+), 58 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 3f5441b82e7ce8..54f5cf4fd586b4 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -21,6 +21,18 @@ Execute without arguments to start the [REPL][]. _For more info about `node inspect`, please see the [debugger][] documentation._ ## Options + + +All options, including V8 options, allow words to be separated by both +dashes (`-`) or underscores (`_`). + +For example, `--pending-deprecation` is equivalent to `--pending_deprecation`. ### `-` From 7ca87b0100d84eddf6f92f3996c2650c18111657 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 22 Sep 2018 20:34:06 +0200 Subject: [PATCH 4/4] =?UTF-8?q?fixup!=20cli:=20normalize=20`=5F`=20?= =?UTF-8?q?=E2=86=92=20`-`=20when=20parsing=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node_options-inl.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 9642b59a2368f8..277121036e519d 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -307,11 +307,10 @@ void OptionsParser::Parse( if (equals_index != std::string::npos) original_name += '='; - { - // 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] = '-'; + // Normalize by replacing `_` with `-` in options. + for (std::string::size_type i = 2; i < name.size(); ++i) { + if (name[i] == '_') + name[i] = '-'; } {