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

Arguments after "end of flags" (--) aren't easily available #8

Closed
jgoz opened this issue Jan 24, 2022 · 8 comments · Fixed by #9
Closed

Arguments after "end of flags" (--) aren't easily available #8

jgoz opened this issue Jan 24, 2022 · 8 comments · Fixed by #9

Comments

@jgoz
Copy link

jgoz commented Jan 24, 2022

Feature request

Add a __ property that only contains the arguments following the end of flags token.

Why?

Arguments passed after the "end of flags" token (--) are appended to _, but there is no way to determine at which point in the array they start. It's often the case that extra args need to be passed to a child process, which requires them to be separated from the "known" args.

With cleye's current design, it's not possible to determine where the extra args begin.

Alternatives

Expose a property containing the index of the first extra arg.

Additional context

No response

@privatenumber privatenumber transferred this issue from privatenumber/cleye Jan 24, 2022
@privatenumber
Copy link
Owner

Moved to type-flag repo since it's type-flag that handles -- parsing.


Thanks for requesting this feature. I needed something similar in git-detect-case-change but I was able to work around it so it wasn't strong enough of a use-case to warrant -- separation.

I think the use-case you described, including scripts like npm run foo -- bar, support the need for this functionality.

This will be a breaking change but I'm happy to make it.

@privatenumber
Copy link
Owner

I'm thinking about creating a .__ property to access arguments after --.

However, it might be confusing to discern between ._ and .__. Minimist uses the ['--'] property, but I don't really want to force users to use the computed property syntax just for this.

Do you have any other ideas?

@jgoz
Copy link
Author

jgoz commented Jan 24, 2022

I think the use-case you described, including scripts like npm run foo -- bar, support the need for this functionality.

That's very close to the case I had in mind.

This will be a breaking change but I'm happy to make it.

This wouldn't need to be a breaking change if you continued appending the extra args to _ but also to a separate array. That's kind of what I had in mind originally.

However, it might be confusing to discern between ._ and .__. Minimist uses the ['--'] property, but I don't really want to force users to use the computed property syntax just for this.

Do you have any other ideas?

Very good points. Maybe .extraArgs or .unknownArgs?

Alternately, it could be a well-known property attached to _, similar to parameter names? Something like _.extraArgs? This would cause a conflict if someone added a parameter named extraArgs, but this issue already kind of exists with length (conflict between a parameter named "length" and the Array property).

@jgoz
Copy link
Author

jgoz commented Jan 24, 2022

Another option to all of this would be:

  • Expose args property that contains all known arguments (similar to flags)
  • Expose unknownArgs property that contains anything passed after -- (similar to unknownFlags)
  • Keep _ as-is

@privatenumber
Copy link
Owner

privatenumber commented Jan 26, 2022

Thank you for the feedback! It was very helpful.

I think I have decided to move forward with _['--'] because:

  • Using a word (eg. extraArgs) as a property on ._ would collide with parameters in Cleye. Good point about length and any other Array prototype methods though, but those are much more predictable as they're standard JS.
  • _['--'] is verbose but also more explicit and clear than trying to make a new term to describe it. I think this is especially important to contributors trying to read the code of a project that uses Cleye/type-flag

I plan on testing it in some of my projects tomorrow before I release it but feel free to give it a try if you'd like and share feedback:

  • If you're using type-flag: npm i 'privatenumber/type-flag#built/end-of-args-property'
  • If you're using cleye: npm i 'privatenumber/cleye#built/end-of-args-property'

@jgoz
Copy link
Author

jgoz commented Jan 26, 2022

Awesome! Thanks for being so receptive to ideas. I’ll give it a try soon

@privatenumber
Copy link
Owner

Available in v2.1.0! Releasing in Cleye soon.

Thanks @jgoz

@privatenumber
Copy link
Owner

Released in Cleye 1.1.0

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

Successfully merging a pull request may close this issue.

2 participants