-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
"--" after "-e <script>" means end-of-options #10651
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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`. | |
|
||
## Synopsis | ||
|
||
`node [options] [v8 options] [script.js | -e "script"] [arguments]` | ||
`node [options] [v8 options] [script.js | -e "script"] [--] [arguments]` | ||
|
||
`node debug [script.js | -e "script" | <host>:<port>] …` | ||
|
||
|
@@ -265,6 +265,15 @@ added: v0.11.15 | |
|
||
Specify ICU data load path. (overrides `NODE_ICU_DATA`) | ||
|
||
### `--` | ||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
Indicate the end of node options. Pass the rest of the arguments to the script. | ||
If no script filename or eval/print script is supplied prior to this, then | ||
the next argument will be used as a script filename. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add this to the man page. |
||
## Environment Variables | ||
|
||
### `NODE_DEBUG=module[,…]` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ const child = require('child_process'); | |
const path = require('path'); | ||
const nodejs = `"${process.execPath}"`; | ||
|
||
if (process.argv.length > 2) { | ||
console.log(process.argv.slice(2).join(' ')); | ||
process.exit(0); | ||
} | ||
|
||
// Assert that nothing is written to stdout. | ||
child.exec(`${nodejs} --eval 42`, common.mustCall((err, stdout, stderr) => { | ||
assert.ifError(err); | ||
|
@@ -133,3 +138,38 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`, | |
assert.strictEqual(proc.stderr, ''); | ||
assert.strictEqual(proc.stdout, 'start\nbeforeExit\nexit\n'); | ||
} | ||
|
||
[ '-arg1', | ||
'-arg1 arg2 --arg3', | ||
'--', | ||
'arg1 -- arg2', | ||
].forEach(function(args) { | ||
|
||
// Ensure that arguments are successfully passed to eval. | ||
const opt = ' --eval "console.log(process.argv.slice(1).join(\' \'))"'; | ||
const cmd = `${nodejs}${opt} -- ${args}`; | ||
child.exec(cmd, common.mustCall(function(err, stdout, stderr) { | ||
assert.strictEqual(stdout, args + '\n'); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(err, null); | ||
})); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you drop the blank line here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// Ensure that arguments are successfully passed to print. | ||
const popt = ' --print "process.argv.slice(1).join(\' \')"'; | ||
const pcmd = `${nodejs}${popt} -- ${args}`; | ||
child.exec(pcmd, common.mustCall(function(err, stdout, stderr) { | ||
assert.strictEqual(stdout, args + '\n'); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(err, null); | ||
})); | ||
|
||
// Ensure that arguments are successfully passed to a script. | ||
// The first argument after '--' should be interpreted as a script | ||
// filename. | ||
const filecmd = `${nodejs} -- ${__filename} ${args}`; | ||
child.exec(filecmd, common.mustCall(function(err, stdout, stderr) { | ||
assert.strictEqual(stdout, args + '\n'); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(err, null); | ||
})); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this is also supposed to work with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by "fails" and "not work"?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except that this is a bug:
The
Except with a file name of Is it out of scope to fix this bug, too, in this PR @jBarz? Should I report this as a bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I take that back, you're correct. Using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would still like to see the tests expanded to cover the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR: After this PR: I can change it to do what @sam-github says it must do: Since node also uses a script name to indicate end-of-options, I would like to clarify what should happen in this case? Should "--" be passed into the script or ignored? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. passed in, so that the script.js can use it to indicate the end of its options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will commit some additional changes and tests as @jasnell mentioned above. Thanks for the feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the man page at
doc/node.1
with this change.