You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the above example, when config command is executed, the command:config listener never gets executed.
After console logging around the Commander source code, I have found out that the reason this doesn't work is that listener is registered on parent (in this context, main program) whereas the emit function is called on a subcommand (config).
Is there any way to bubble events up? It seems to be quite natural to listen to command:<name> on the main object, otherwise, there's no difference from attaching a listener to config vs tweaking action handler.
The text was updated successfully, but these errors were encountered:
In your example, the emit for command:config should indeed be called on program. After some investigation, I think this is a bug introduced in Commander v5. The refactor of the code changed where the emit is called.
Hey,
Not sure if I am using this correctly, but it does seem to be a good use case and not far away from working.
My program is as follows:
In the above example, when
config
command is executed, thecommand:config
listener never gets executed.After console logging around the Commander source code, I have found out that the reason this doesn't work is that listener is registered on
parent
(in this context, main program) whereas theemit
function is called on a subcommand (config
).Changing
this.emit
tothis.parent.emit
fixes it https://github.com/tj/commander.js/blob/master/index.js#L1003Is there any way to bubble events up? It seems to be quite natural to listen to
command:<name>
on the main object, otherwise, there's no difference from attaching a listener toconfig
vs tweaking action handler.The text was updated successfully, but these errors were encountered: