-
-
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
[Feature Request] postParse
hooks
#1976
Comments
On second thought, |
The scenario that proved messy to cover in #1902 #1913 is the no-action-hander fall-through case. I think a hook to do post-parse-processing is a potentially useful new location. With a good name. 😆 I wonder whether this would be easy to do by adding another layer and calling the hook after: Lines 1259 to 1265 in 4ef19fa
|
Exactly. As I said, #1902 had already introduced this new event. I closed the PR myself because relying on the hook infrastructure seemed too messy, but it actually doesn't look so bad now when I think about it. What I did not realize back then is that
Also, I was clinging on the idea of letting users of the library decide at which hook processing stage to add the await hook that originally came up in #1900 (comment) too much. It wasn't very useful even when users had to call Taking all that into consideration, the code changes in #1902 could be simplified to only include
#1915 was closed because it was too complex. Here is how the reasons in the closing comment could be countered if this new suggestion from above is implemented.
True, but unlike most other enhancement I've suggested over the past month, this one is motivated by a real use case in one of my projects.
The only complication due to the new awaiting functionality is that
Not really, since overwritten option values are not handled specially anymore. There is only one line responsible for rejection handling, namely this one from handledResult = result.then(x => x, handleError); If the rejection is not due to an invalid argument, it is supposed to be handled by the library user.
No additional places where
The awaiting of both the option and argument values is now done in the same place and only once. Resolution is out-of-order only for options and arguments of one particular command in the subcommand chain, but that is expected when using async features. I cannot think of any problems the enhancement would introduce for users of the library because they wouldn't get to see the non-awaited values anywhere when using
The new hook event and the fact overwritten values are not handled specially anymore make the implementation of the awaiting functionality quite simple even in the general case. I might open a PR implementing this suggestion later if it's okay with you. |
I am thinking about giving up the
Another option I've been thinking of is
Okay for "inner" commands, but not the leaf command because argParsers for command-arguments haven't been run yet. The two places where I think the event should be fired are
|
Right. I thought it seemed too easy (else we would have found it before!). |
This issue has not had any activity in over six months. It isn't likely to get acted on due to this report. The new hook would be useful for some cases, but is messy, so will wait for more interest. See comment for more background: #1976 (comment) Feel free to open a new issue if it comes up again, with new information and renewed interest. Thank you for your contributions. |
I am currently working on recommander, a library extending Commander's functionality by features that I consider reasonable additions despite there having been little interest shown for them here. It already has async argParser support (#1900), and I would like to add
Option.requires()
to solve #1802 and something likeOption.unrequires()
to solve #1855.Both the checks of the option requirement constraints and the awaiting of options and arguments have to be done after the parsing is finished, so it would be great to have a hook event fired at this point.
postParse
would be a good name for it.Currently, the same code has to be run to in three places to simulate such a hook:
preSubcommand
hookpreAction
hook.parse()
/.parseAsync()
calls in case it does not have an action handlerTo enable the root command on which
.parse()
/.parseAsync()
was called to find the leaf command, the dispatched subcommand needs to be stored in a variable at each level of the command hierarchy. Here are the code lines responsible for this in recommander/lib/command.js:Very annoying and unnecessary! This shows
postParse
hooks are a must-have feature for subclasses.The text was updated successfully, but these errors were encountered: