Skip to content

Commit b75822d

Browse files
addaleaxruyadorno
authored andcommitted
doc,test: specify and test CLI option precedence rules
Refs: #35098 (comment) PR-URL: #35106 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent aa93c1c commit b75822d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/api/cli.md

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ dashes (`-`) or underscores (`_`).
3434

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

37+
If an option that takes a single value, for example `--max-http-header-size`,
38+
is passed more than once, then the last passed value will be used. Options
39+
from the command line take precedence over options passed through the
40+
[`NODE_OPTIONS`][] environment variable.
41+
3742
### `-`
3843
<!-- YAML
3944
added: v8.0.0
@@ -1554,6 +1559,7 @@ $ node --max-old-space-size=1536 index.js
15541559
[`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait
15551560
[`Buffer`]: buffer.html#buffer_class_buffer
15561561
[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer
1562+
[`NODE_OPTIONS`]: #cli_node_options_options
15571563
[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn
15581564
[`tls.DEFAULT_MAX_VERSION`]: tls.html#tls_tls_default_max_version
15591565
[`tls.DEFAULT_MIN_VERSION`]: tls.html#tls_tls_default_min_version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
6+
// The last option on the command line takes precedence:
7+
assert.strictEqual(spawnSync(process.execPath, [
8+
'--max-http-header-size=1234',
9+
'--max-http-header-size=5678',
10+
'-p', 'http.maxHeaderSize'
11+
], {
12+
encoding: 'utf8'
13+
}).stdout.trim(), '5678');
14+
15+
// The command line takes precedence over NODE_OPTIONS:
16+
assert.strictEqual(spawnSync(process.execPath, [
17+
'--max-http-header-size=5678',
18+
'-p', 'http.maxHeaderSize'
19+
], {
20+
encoding: 'utf8',
21+
env: { ...process.env, NODE_OPTIONS: '--max-http-header-size=1234' }
22+
}).stdout.trim(), '5678');

0 commit comments

Comments
 (0)