-
Notifications
You must be signed in to change notification settings - Fork 118
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
Prefer sending args to _
when both halt-at-non-option
and populate--
are enabled
#456
Conversation
…hen a non-option is encountered
@Toberumono Let me know if you're able to verify that this fix works for you! |
@kherock That won't work because it's still going to treat the first command name as an invalid "argument", thereby blocking parsing of anything else. If you want to make this work without a flag, yargs-parser is going to need to be able to test whether a command is valid. |
I see, so global options that you're sending to your subcommands aren't getting parsed due to @bcoe correct me if I'm wrong, but this means that |
Again, your fix breaks parsing of commands at every level, not just subcommands, and not just for arguments. What you are suggesting would also mean copying the same parser configuration object into every subcommand, which is both inconvenient and incredibly error-prone, especially when factoring in subcommands that don't necessarily have arguments and trees of subcommands with uneven depths. (See git-remote for an example of both) |
I can't stress this enough, what you are experiencing from #438's merge is a latent bug. You should encounter similar parsing problems on older versions if you use This PR should fix some things up for you, but what does not account for in your example are the inputs for
In this case, it's basically in the spec of |
First, while it may appear on the surface that this PR fixes some things, it's just kicking the can down the road - forcibly shunting stuff into '_' instead of '--' isn't a proper solution to the problem of, "yargs-parser doesn't understand that commands can exist". |
@Toberumono I understand the frustration here, I'm sorry that I broke your stuff. This PR also isn't supposed to be a hacked-together-knee-jerk reaction to your problem. I depend on this library to be robust as well! So for me, I need #438 because I need precisely what |
@kherock I realize that you weren't intending to break anything. And thank you for the apology. It wasn't your fault that it broke - the patch was a logical change in terms of following the words that the flags say. The company I work for has been shifting to using node for larger-scale process automation stuff, and the control scripts use node because the language was already available on those machines. One of the automatic updates nearly pulled in that change after I had (supposedly) pinned the version to 21.0.1, hence me wanting a flag (turns out that yarn doesn't actually obey explicit version-pinning unless you specify them in a bonus area). I'm sorry for being a bit short - I was juggling a couple of things and praying that I didn't get a call at the time. With regards to the flag I was proposing, it's supposed just toggle the |
Appreciate the context, and no hard feelings. Unless I'm missing something, I think you can just turn off halt-at-non-option to restore your previous behavior. Before v21.1 In order to actually leverage it with subcommands, it does seem like you'll need an unfortunate amount of refactoring to make it do useful work, given the existing capabilities of this library. I think the command tree solution makes a lot of sense. |
Okay. So. After going through my system with several fine-toothed combs and a complete deletion of node-, npm-, and yarn-related cache I could find, it looks like some of the consistency problems that were occurring were actually due to yarn/npm installing two completely separate versions of the library simultaneously. |
Good to hear. Before I consider closing this let me verify that yargs itself doesn't already have some special handling for |
I think that |
I agree that I'm leaving more comments in the original thread. |
Fixes (part of) #453
There is currently an undocumented interaction between
halt-at-non-option
andpopulate--
where the remaining args are sent to--
whenpopulate--
is true, and_
when it's false. There doesn't seem to be any tests enforcing this behavior, and it causes subcommand handling inyargs
to break down. Given that this was a latent bug when combined withunknown-options-as-args: true
(which was fixed in v21.1.0 by #438), I think it will be the least disruptive to ensure thatpopulate--
has no effect on the behavior of this parse option.