Skip to content

Commit

Permalink
First cut at beforeExec
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed May 9, 2021
1 parent f2f9390 commit 216aa2c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Expand Up @@ -998,7 +998,7 @@ class Command extends EventEmitter {
*/

hook(event, listener) {
const allowedValues = ['beforeAction', 'afterAction'];
const allowedValues = ['beforeAction', 'afterAction', 'beforeExec'];
if (!allowedValues.includes(event)) {
throw new Error(`Unexpected value for event passed to hook : '${event}'.
Expecting one of '${allowedValues.join("', '")}'`);
Expand Down Expand Up @@ -1606,10 +1606,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
if (!subCommand) this.help({ error: true });

if (subCommand._executableHandler) {
this._executeSubCommand(subCommand, operands.concat(unknown));
} else {
return subCommand._parseCommand(operands, unknown);
}
let execResult;
execResult = this._chainOrCallHooks(execResult, 'beforeExec');
execResult = this._chainOrCall(execResult, () => this._executeSubCommand(subCommand, operands.concat(unknown)));
// 'afterExec' is tricky with subcommand close triggering exit
return execResult;
};

return subCommand._parseCommand(operands, unknown);
};

/**
Expand Down

0 comments on commit 216aa2c

Please sign in to comment.