Skip to content
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

Filenames / dirnames with a leading hyphen: a CLI argument issue #10661

Closed
vsemozhetbyt opened this issue Jan 6, 2017 · 16 comments
Closed

Filenames / dirnames with a leading hyphen: a CLI argument issue #10661

vsemozhetbyt opened this issue Jan 6, 2017 · 16 comments
Labels
question Issues that look for answers.

Comments

@vsemozhetbyt
Copy link
Contributor

  • Version: 7.4.0
  • Platform: Windows 7 x64
  • Subsystem: cli

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.

@addaleax
Copy link
Member

addaleax commented 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
Copy link
Contributor

jBarz commented 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
Copy link
Member

jasnell commented 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
Copy link
Member

addaleax commented Jan 6, 2017

The only way to do this would be to introduce a new option like

Why wouldn’t -- work?

@jBarz
Copy link
Contributor

jBarz commented Jan 6, 2017

Do you mean
node -- -test.js?

@addaleax
Copy link
Member

addaleax commented Jan 6, 2017

@jBarz exactly. ;) The solution in your PR seems tailored for -e/-p but I’m not sure it actually needs to be?

@mscdex mscdex added the question Issues that look for answers. label Jan 6, 2017
@jBarz
Copy link
Contributor

jBarz commented Jan 6, 2017

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.

@addaleax
Copy link
Member

addaleax commented 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 != nullptr bit but I may be mistaken.

@Fishrock123
Copy link
Contributor

I do not think that -- is the correct syntax for this. node ./-test.js seems like the best way to go.

@addaleax
Copy link
Member

addaleax commented Jan 6, 2017

I do not think that -- is the correct syntax for this.

I mean… it’s pretty standard to support it that way?

@Fishrock123
Copy link
Contributor

I think that conflicts with the potential use in #10651 though?

@sam-github
Copy link
Contributor

@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
Copy link
Contributor

jBarz commented 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
Copy link
Contributor

I could be missing a corner case, and the distinction between node and v8, but above is my understanding.

@jBarz
Copy link
Contributor

jBarz commented Feb 15, 2017

This can be closed.
0a9f360 fixes the "--" option so that you can now do the following.
node -- -test.js

@addaleax
Copy link
Member

Yup, this should work fine now. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

7 participants