Skip to content

Commit

Permalink
Use getCommandAndParents for array of parents (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Jul 12, 2021
1 parent 56c4108 commit 4be69f1
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
};

/**
Expand Down

0 comments on commit 4be69f1

Please sign in to comment.