Skip to content

Commit

Permalink
doc,test: specify and test CLI option precedence rules
Browse files Browse the repository at this point in the history
Refs: #35098 (comment)

PR-URL: #35106
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
addaleax committed Sep 11, 2020
1 parent 4f176c9 commit 02e9255
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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');

0 comments on commit 02e9255

Please sign in to comment.