Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc,test: specify and test CLI option precedence rules
  • Loading branch information
addaleax committed Sep 8, 2020
commit 559197b1ba7aed4853f074269b35d2eed14c1c51
6 changes: 6 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ dashes (`-`) or underscores (`_`).

For example, `--pending-deprecation` is equivalent to `--pending_deprecation`.

If an option that takes a single value, for example `--max-http-header-size`,
is passed more than once, then the last passed value will be used. Options
from the command line take precedence over options passed through the
[`NODE_OPTIONS`][] environment variable.

### `-`
<!-- YAML
added: v8.0.0
Expand Down Expand Up @@ -1588,6 +1593,7 @@ $ node --max-old-space-size=1536 index.js
[`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait
[`Buffer`]: buffer.html#buffer_class_buffer
[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer
[`NODE_OPTIONS`]: #cli_node_options_options
[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn
[`tls.DEFAULT_MAX_VERSION`]: tls.html#tls_tls_default_max_version
[`tls.DEFAULT_MIN_VERSION`]: tls.html#tls_tls_default_min_version
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-cli-options-precedence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');

// The last option on the command line takes precedence:
assert.strictEqual(spawnSync(process.execPath, [
'--max-http-header-size=1234',
'--max-http-header-size=5678',
'-p', 'http.maxHeaderSize'
], {
encoding: 'utf8'
}).stdout.trim(), '5678');

// The command line takes precedence over NODE_OPTIONS:
assert.strictEqual(spawnSync(process.execPath, [
'--max-http-header-size=5678',
'-p', 'http.maxHeaderSize'
], {
encoding: 'utf8',
env: { ...process.env, NODE_OPTIONS: '--max-http-header-size=1234' }
}).stdout.trim(), '5678');