diff --git a/lib/command.js b/lib/command.js index 6150c53e5..4d080b172 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1662,14 +1662,7 @@ Expecting one of '${allowedValues.join("', '")}'`); } const context = this._getHelpContext(contextOptions); - const groupListeners = []; - let command = this; - while (command) { - groupListeners.push(command); // ordered from current command to root - command = command.parent; - } - - groupListeners.slice().reverse().forEach(command => command.emit('beforeAllHelp', context)); + getCommandAndParents(this).reverse().forEach(command => command.emit('beforeAllHelp', context)); this.emit('beforeHelp', context); let helpInformation = this.helpInformation(context); @@ -1683,7 +1676,7 @@ Expecting one of '${allowedValues.join("', '")}'`); this.emit(this._helpLongFlag); // deprecated this.emit('afterHelp', context); - groupListeners.forEach(command => command.emit('afterAllHelp', context)); + getCommandAndParents(this).forEach(command => command.emit('afterAllHelp', context)); }; /**