GeezerVison is showing github.com — src: support "--" after "-e" as end-of-options · nodejs/node@c408a3b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +10-1Lines changed: 10 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,7 @@ To view this documentation as a manual page in your terminal, run `man node`. | 10 | 10 |
| 11 | 11 | ## Synopsis | 12 | 12 |
| 13 | | -`node [options] [v8 options] [script.js | -e "script"] [arguments]` | | 13 | +`node [options] [v8 options] [script.js | -e "script"] [--] [arguments]` | 14 | 14 |
| 15 | 15 | `node debug [script.js | -e "script" | <host>:<port>] …` | 16 | 16 |
| @@ -251,6 +251,15 @@ added: v0.11.15 | 251 | 251 |
| 252 | 252 | Specify ICU data load path. (overrides `NODE_ICU_DATA`) | 253 | 253 |
| | 254 | +### `--` | | 255 | +<!-- YAML | | 256 | +added: REPLACEME | | 257 | +--> | | 258 | + | | 259 | +Indicate the end of node options. Pass the rest of the arguments to the script. | | 260 | +If no script filename or eval/print script is supplied prior to this, then | | 261 | +the next argument will be used as a script filename. | | 262 | + | 254 | 263 | ## Environment Variables | 255 | 264 |
| 256 | 265 | ### `NODE_DEBUG=module[,…]` | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,6 +37,7 @@ node \- Server-side JavaScript runtime | 37 | 37 | .RI [ script.js \ | | 38 | 38 | .B -e | 39 | 39 | .RI \&" script \&"] | | 40 | +.B [--] | 40 | 41 | .RI [ arguments ] | 41 | 42 | .br | 42 | 43 | .B node debug | @@ -175,6 +176,13 @@ used to enable FIPS-compliant crypto if Node.js is built with | 175 | 176 | .BR \-\-icu\-data\-dir =\fIfile\fR | 176 | 177 | Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR) | 177 | 178 |
| | 179 | +.TP | | 180 | +.BR \-\-\fR | | 181 | +Indicate the end of node options. Pass the rest of the arguments to the script. | | 182 | + | | 183 | +If no script filename or eval/print script is supplied prior to this, then | | 184 | +the next argument will be used as a script filename. | | 185 | + | 178 | 186 | .SH ENVIRONMENT VARIABLES | 179 | 187 |
| 180 | 188 | .TP | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3860,6 +3860,9 @@ static void ParseArgs(int* argc, | 3860 | 3860 | } else if (strcmp(arg, "--expose-internals") == 0 || | 3861 | 3861 | strcmp(arg, "--expose_internals") == 0) { | 3862 | 3862 | // consumed in js | | 3863 | + } else if (strcmp(arg, "--") == 0) { | | 3864 | + index += 1; | | 3865 | + break; | 3863 | 3866 | } else { | 3864 | 3867 | // V8 option. Pass through as-is. | 3865 | 3868 | new_v8_argv[new_v8_argc] = arg; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,11 @@ const child = require('child_process'); | 12 | 12 | const path = require('path'); | 13 | 13 | const nodejs = `"${process.execPath}"`; | 14 | 14 |
| | 15 | +if (process.argv.length > 2) { | | 16 | + console.log(process.argv.slice(2).join(' ')); | | 17 | + process.exit(0); | | 18 | +} | | 19 | + | 15 | 20 | // Assert that nothing is written to stdout. | 16 | 21 | child.exec(`${nodejs} --eval 42`, common.mustCall((err, stdout, stderr) => { | 17 | 22 | assert.ifError(err); | @@ -163,3 +168,38 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`, | 163 | 168 | }); | 164 | 169 | proc.send('ping'); | 165 | 170 | } | | 171 | + | | 172 | +[ '-arg1', | | 173 | + '-arg1 arg2 --arg3', | | 174 | + '--', | | 175 | + 'arg1 -- arg2', | | 176 | +].forEach(function(args) { | | 177 | + | | 178 | + // Ensure that arguments are successfully passed to eval. | | 179 | + const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"'; | | 180 | + const cmd = `${nodejs}${opt} -- ${args}`; | | 181 | + child.exec(cmd, common.mustCall(function(err, stdout, stderr) { | | 182 | + assert.strictEqual(stdout, args + '\n'); | | 183 | + assert.strictEqual(stderr, ''); | | 184 | + assert.strictEqual(err, null); | | 185 | + })); | | 186 | + | | 187 | + // Ensure that arguments are successfully passed to print. | | 188 | + const popt = ' --print "process.argv.slice(1).join(\' \')"'; | | 189 | + const pcmd = `${nodejs}${popt} -- ${args}`; | | 190 | + child.exec(pcmd, common.mustCall(function(err, stdout, stderr) { | | 191 | + assert.strictEqual(stdout, args + '\n'); | | 192 | + assert.strictEqual(stderr, ''); | | 193 | + assert.strictEqual(err, null); | | 194 | + })); | | 195 | + | | 196 | + // Ensure that arguments are successfully passed to a script. | | 197 | + // The first argument after '--' should be interpreted as a script | | 198 | + // filename. | | 199 | + const filecmd = `${nodejs} -- ${__filename} ${args}`; | | 200 | + child.exec(filecmd, common.mustCall(function(err, stdout, stderr) { | | 201 | + assert.strictEqual(stdout, args + '\n'); | | 202 | + assert.strictEqual(stderr, ''); | | 203 | + assert.strictEqual(err, null); | | 204 | + })); | | 205 | +}); |
|