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

Add support for "--" option #73

Closed
atavakoli opened this issue Dec 21, 2017 · 10 comments
Closed

Add support for "--" option #73

atavakoli opened this issue Dec 21, 2017 · 10 comments

Comments

@atavakoli
Copy link

I'm requesting support for the POSIX-recommended, -- argument:

The argument ‘--’ terminates all options; any following arguments are treated as non-option arguments, even if they begin with a hyphen.

Encountering a -- could just add all the following arguments to the option having defaultOption: true, or to the _unknown property if no defaultOption is set and partial is true; otherwise, an exception could be thrown.

@75lb
Copy link
Owner

75lb commented Dec 22, 2017

Hi, yes this functionality is planned for the next release. I will post more detail about how it will work here once I get sufficient time. Let me know if you have any further ideas or requests for improvement.

@atavakoli
Copy link
Author

@75lb thanks. Which issue in that PR covers the -- option?

@75lb
Copy link
Owner

75lb commented Dec 29, 2017

The idea was introduced by #53 and is still maturing (a WIP).

@75lb
Copy link
Owner

75lb commented Jan 7, 2018

do you support the idea of having a stop parsing at first unknown feature? Some users would prefer if the first unknown option/value parsed acted as the -- style terminator.

In this example, the author could define options for -v and --os and enable the stop parsing at first unknown feature, meaning ls, -l and -a would be written to _unknown.

$ example -v --os centos ls -l -a

The above would be equivalent to this but saves the user needing to add --:

$ example -v --os centos -- ls -l -a

@atavakoli
Copy link
Author

do you support the idea of having a stop parsing at first unknown feature?

I think this is a fair compromise, as people interested in implementing POSIX-style -- handling I can just check if the 1st unknown option is "--" and ignore it.

Just to be certain, what you're describing is the existing behavior when using {partial: true}, right?

@75lb
Copy link
Owner

75lb commented Jan 9, 2018

no, "stop parsing at first unknown" is a new feature i'm planning to implement. The existing {partial: true} behaviour reports all unknown args. The "stop parsing at first unknown" will stop parsing altogether at the first unknown arg it meets, writing off the remaining args as _unknown whether they are known or not.

I'm not suggesting we compromise btw. We can have both "stop parsing at first unknown" and "stop parsing at --" as features.

@atavakoli
Copy link
Author

Ah ok, that makes sense. From my side, I'm happy with whichever (or both) you decide to implement.

@75lb 75lb mentioned this issue Jan 13, 2018
@75lb
Copy link
Owner

75lb commented Jan 16, 2018

does this explanation of -- make sense?

You can try it using the prerelease.

$ npm install command-line-args@next

@75lb
Copy link
Owner

75lb commented Jan 17, 2018

Implemented in v5.0.0.

@75lb 75lb closed this as completed Jan 17, 2018
@atavakoli
Copy link
Author

Thanks @75lb, and the explanation makes sense (glad you went into detail on how to use it to remove ambiguity).

Looking forward to using it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants