diff options
author | Michaël Zasso <targos@protonmail.com> | 2021-06-13 13:46:35 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-06-21 21:18:20 +0300 |
commit | 1bbe66f432591aea83555d27dd76c55fea040a0d (patch) | |
tree | 112ae06f8c3c305341967af71acbeb82c1b0d02f /src/node_options.cc | |
parent | 86d6d816fd41bb015488c8a0022cc9cf4d1a174b (diff) |
src: allow to negate boolean CLI flags
This change allows all boolean flags to be negated using the `--no-`
prefix.
Flags that are `true` by default (for example `--deprecation`) are
still documented as negations.
With this change, it becomes possible to easily flip the default
value of a boolean flag and to override the value of a flag passed
in the NODE_OPTIONS environment variable.
`process.allowedNodeEnvironmentFlags` contains both the negated and
non-negated versions of boolean flags.
Co-authored-by: Anna Henningsen <anna@addaleax.net>
PR-URL: https://github.com/nodejs/node/pull/39023
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/node_options.cc')
-rw-r--r-- | src/node_options.cc | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/node_options.cc b/src/node_options.cc index bf18d77d7d1..1e3659cd00c 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -391,18 +391,21 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { kAllowedInEnvironment); AddAlias("--es-module-specifier-resolution", "--experimental-specifier-resolution"); - AddOption("--no-deprecation", + AddOption("--deprecation", "silence deprecation warnings", - &EnvironmentOptions::no_deprecation, - kAllowedInEnvironment); - AddOption("--no-force-async-hooks-checks", + &EnvironmentOptions::deprecation, + kAllowedInEnvironment, + true); + AddOption("--force-async-hooks-checks", "disable checks for async_hooks", - &EnvironmentOptions::no_force_async_hooks_checks, - kAllowedInEnvironment); - AddOption("--no-warnings", + &EnvironmentOptions::force_async_hooks_checks, + kAllowedInEnvironment, + true); + AddOption("--warnings", "silence all process warnings", - &EnvironmentOptions::no_warnings, - kAllowedInEnvironment); + &EnvironmentOptions::warnings, + kAllowedInEnvironment, + true); AddOption("--force-context-aware", "disable loading non-context-aware addons", &EnvironmentOptions::force_context_aware, @@ -594,9 +597,9 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( "track heap object allocations for heap snapshots", &PerIsolateOptions::track_heap_objects, kAllowedInEnvironment); - AddOption("--no-node-snapshot", + AddOption("--node-snapshot", "", // It's a debug-only option. - &PerIsolateOptions::no_node_snapshot, + &PerIsolateOptions::node_snapshot, kAllowedInEnvironment); // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS. @@ -1014,6 +1017,10 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) { env->type_string(), Integer::New(isolate, static_cast<int>(option_info.type))) .FromMaybe(false) || + !info->Set(context, + env->default_is_true_string(), + Boolean::New(isolate, option_info.default_is_true)) + .FromMaybe(false) || info->Set(context, env->value_string(), value).IsNothing() || options->Set(context, name, info).IsEmpty()) { return; |