-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
How to stop parsing for options after first argument? #1127
Comments
No, but you can use
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
|
Both. You are actually adding arguments to the root level command in your example! See https://github.com/tj/commander.js#specify-the-argument-syntax
|
Positional option parsing does come up sometimes in issues, and I am interested, if you want to look into it. I suspect it may be tricky to add! |
In the mean time I switched to yargs-parser that offers that option. And since my lib is still small regarding options, I'm handwriting the usage part for now. |
Related previous issue: #1033 Closing as details provided and OP no longer interested. |
Actually I'm still not convinced by my move away from commander. I like it's "fail early" approach more than the flexibility others offer. Where/How would you suggest to add this feature? |
(The approach of splitting the arguments is flawed because it can change the argument order, and I am hoping to eventually have a go at rewriting the logic... Edit: working on it now...) Note there is special processing for
Yes. Backwards compatibility is important. My first thought is most people will either want (all) global options, or (all) positional options. I'm thinking there is a new call to switch the default behaviour (rather than control per option). e.g.
Good luck. I'm busy elsewhere in the code so won't be doing a deep dive at the moment, but ask if you have questions I might be able to help with in the meantime. |
Opened PR for rewrite of |
If I understand your last message correctly, it will be much easier to add the feature I requested in v5 / when that PR landed, right? (Sorry for the above redundant "noise", was just a rebase of a branch. I removed the link from the commit message now.) |
A little easier, and a lot less likely to get a merge conflict. :-) |
Second PR open now too: #1145 |
Found another related issue for positional options: #797 |
No activity in a month. I did some research and rethinking the higher level goals. Closing in favour of #1229. |
Pull Request opened to add |
Sorry, currently I'm having a hard time following all the threads and descriptions to solve my requirement. Thx |
Just add const runnable$ = '<runnable> [args...]';
new Command('runex').usage(`[options] ${runnable$}`)
.passThroughOptions() // <------
.option(
'-r, --require <module>', '0..n modules for node to require', collectDistinct, []
)
.arguments(runnable$)
.action((runnable, args, options, command) => {
console.log(`runex: ${runnable} ${args}`);
})
.parse(process.argv)
|
I have the following usage pattern:
runex [options] <module> [args...]
where args should be everything that is listed after
module
, even if it matches any option I have configured using.option()
.Is there a way to tell commander to stop on the first positional argument it found and pass the rest to
args
?Or a way to hook into commander event listeners to achieve this?
(A related question of understanding: are arguments only supported on commands or also on the root level?)
I tried the following code:
but the following case is not working as expected:
runex -r ts-node/register path/to/script -r
since it exits with
error: option '-r, --require <module>' argument missing
I'm not sure but #193 might be related.
I'm happy to support adding this as a new option.
The text was updated successfully, but these errors were encountered: