You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Filenames / dirnames with a leading hyphen: a CLI argument issue #10661
I don't know if this is a deprecated style in *nix to start filenames with a hyphen, but in Windows, it seems there are no shell problems with it: dir -test or type -test.txt are OK. However, Node.js confuses these names with arguments:
node -test.js
node: bad option: -test.js
node -test\test.js
node: bad option: -test\test.js
If this is a wontfix, maybe it worth to be documented in the 'Command Line Options' doc.
Yes, that would work ! My reason for using "--" in #10651 comes from the POSIX.2 standard
Guideline 10: The argument "--" should be accepted as a delimiter
indicating the end of options. Any following
arguments should be treated as operands, even if they
begin with the '-' character. The "--" argument
should not be used as an option or as an operand.
So using the "--" for any other purpose would deviate from other unix tools, I think.
@jBarz Okay, would you want to update the PR with this then? :) It looks to me like you’d just need to drop the && eval_string != nullptr bit but I may be mistaken.
@jBarz I don't understand why the -- suggestion (node -- -test.js) conflicts with the docs you quote, or with #10651. Perhaps the word "operand" means something different to you than to @addaleax and I?
Traditional UNIX usage, which is what is usually specified by POSIX, is that getopt() and similar stop treating - to be meaningful after the --, which seems to be called for here.
Ahh, I initially understood operands to be just the args passed into the script. i.e. node <options> script.js <operands>
But I believe what you are saying is that the operands include the script name. i.e. node <options> <operands>
where operands = "<script name> <arg1> <arg2> ..."
Activity
addaleax commentedon Jan 6, 2017
The “standard” way of working around that problem would be using
node ./-test.js.But maybe #10651 could be updated to address this use case, too? /cc @jBarz
jBarz commentedon Jan 6, 2017
The only way to do this would be to introduce a new option like
-f <filename>So CLI usage now becomes
node [options] [v8 options] [ [ -f ] script.js | -e "script"] [arguments]The code change wouldn't be trivial in my estimation so probably better to open a separate PR.
jasnell commentedon Jan 6, 2017
I'd rather not introduce a new command line flag for this, especially given that there are ways of working around it already.
addaleax commentedon Jan 6, 2017
Why wouldn’t
--work?jBarz commentedon Jan 6, 2017
Do you mean
node -- -test.js?addaleax commentedon Jan 6, 2017
@jBarz exactly. ;) The solution in your PR seems tailored for
-e/-pbut I’m not sure it actually needs to be?jBarz commentedon Jan 6, 2017
Yes, that would work ! My reason for using "--" in #10651 comes from the POSIX.2 standard
So using the "--" for any other purpose would deviate from other unix tools, I think.
addaleax commentedon Jan 6, 2017
@jBarz Okay, would you want to update the PR with this then? :) It looks to me like you’d just need to drop the
&& eval_string != nullptrbit but I may be mistaken.Fishrock123 commentedon Jan 6, 2017
I do not think that
--is the correct syntax for this.node ./-test.jsseems like the best way to go.addaleax commentedon Jan 6, 2017
I mean… it’s pretty standard to support it that way?
Fishrock123 commentedon Jan 8, 2017
I think that conflicts with the potential use in #10651 though?
sam-github commentedon Jan 9, 2017
@jBarz I don't understand why the
--suggestion (node -- -test.js) conflicts with the docs you quote, or with #10651. Perhaps the word "operand" means something different to you than to @addaleax and I?Traditional UNIX usage, which is what is usually specified by POSIX, is that getopt() and similar stop treating
-to be meaningful after the--, which seems to be called for here.The
./trick is also time-honoured.What is the distinction you are drawing?
jBarz commentedon Jan 9, 2017
Ahh, I initially understood operands to be just the args passed into the script. i.e.
node <options> script.js <operands>But I believe what you are saying is that the operands include the script name. i.e.
node <options> <operands>where
operands = "<script name> <arg1> <arg2> ..."sam-github commentedon Jan 9, 2017
I could be missing a corner case, and the distinction between node and v8, but above is my understanding.
jBarz commentedon Feb 15, 2017
This can be closed.
0a9f360 fixes the "--" option so that you can now do the following.
node -- -test.jsaddaleax commentedon Feb 15, 2017
Yup, this should work fine now. :)