Skip to content
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

src: clarify OptionEnvvarSettings member names #45057

Merged
merged 1 commit into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/internal/process/per_thread.js
Expand Up @@ -267,14 +267,14 @@ const trailingValuesRegex = /=.*$/;
// from data in the config binding.
function buildAllowedFlags() {
const {
envSettings: { kAllowedInEnvironment },
envSettings: { kAllowedInEnvvar },
types: { kBoolean },
} = internalBinding('options');
const { options, aliases } = require('internal/options');

const allowedNodeEnvironmentFlags = [];
for (const { 0: name, 1: info } of options) {
if (info.envVarSettings === kAllowedInEnvironment) {
if (info.envVarSettings === kAllowedInEnvvar) {
ArrayPrototypePush(allowedNodeEnvironmentFlags, name);
if (info.type === kBoolean) {
const negatedName = `--no-${name.slice(2)}`;
Expand All @@ -291,7 +291,7 @@ function buildAllowedFlags() {
ArrayPrototypeSplice(recursiveExpansion, 0, 1);
return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
}
return options.get(to).envVarSettings === kAllowedInEnvironment;
return options.get(to).envVarSettings === kAllowedInEnvvar;
}
for (const { 0: from, 1: expansion } of aliases) {
if (ArrayPrototypeEvery(expansion, isAccepted)) {
Expand Down
6 changes: 3 additions & 3 deletions src/node.cc
Expand Up @@ -769,15 +769,15 @@ static ExitCode InitializeNodeWithArgsInternal(
env_argv.insert(env_argv.begin(), argv->at(0));

const ExitCode exit_code = ProcessGlobalArgsInternal(
&env_argv, nullptr, errors, kAllowedInEnvironment);
&env_argv, nullptr, errors, kAllowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) return exit_code;
}
}
#endif

if (!(flags & ProcessInitializationFlags::kDisableCLIOptions)) {
const ExitCode exit_code = ProcessGlobalArgsInternal(
argv, exec_argv, errors, kDisallowedInEnvironment);
const ExitCode exit_code =
ProcessGlobalArgsInternal(argv, exec_argv, errors, kDisallowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) return exit_code;
}

Expand Down
19 changes: 17 additions & 2 deletions src/node.h
Expand Up @@ -349,10 +349,25 @@ inline std::unique_ptr<InitializationResult> InitializeOncePerProcess(
}

enum OptionEnvvarSettings {
kAllowedInEnvironment,
kDisallowedInEnvironment
// Allow the options to be set via the environment variable, like
// `NODE_OPTIONS`.
kAllowedInEnvvar = 0,
legendecas marked this conversation as resolved.
Show resolved Hide resolved
// Disallow the options to be set via the environment variable, like
// `NODE_OPTIONS`.
kDisallowedInEnvvar = 1,
// Deprecated, use kAllowedInEnvvar instead.
kAllowedInEnvironment = kAllowedInEnvvar,
// Deprecated, use kDisallowedInEnvvar instead.
kDisallowedInEnvironment = kDisallowedInEnvvar,
};

// Process the arguments and set up the per-process options.
// If the `settings` is set as OptionEnvvarSettings::kAllowedInEnvvar, the
// options that are allowed in the environment variable are processed. Options
// that are disallowed to be set via environment variable are processed as
// errors.
// Otherwise all the options that are disallowed (and those are allowed) to be
// set via environment variable are processed.
NODE_EXTERN int ProcessGlobalArgs(std::vector<std::string>* args,
std::vector<std::string>* exec_args,
std::vector<std::string>* errors,
Expand Down
6 changes: 3 additions & 3 deletions src/node_options-inl.h
Expand Up @@ -302,7 +302,7 @@ void OptionsParser<Options>::Parse(
const std::string arg = args.pop_first();

if (arg == "--") {
if (required_env_settings == kAllowedInEnvironment)
if (required_env_settings == kAllowedInEnvvar)
errors->push_back(NotAllowedInEnvErr("--"));
break;
}
Expand Down Expand Up @@ -374,8 +374,8 @@ void OptionsParser<Options>::Parse(
auto it = options_.find(name);

if ((it == options_.end() ||
it->second.env_setting == kDisallowedInEnvironment) &&
required_env_settings == kAllowedInEnvironment) {
it->second.env_setting == kDisallowedInEnvvar) &&
required_env_settings == kAllowedInEnvvar) {
errors->push_back(NotAllowedInEnvErr(original_name));
break;
}
Expand Down