Skip to content

Commit

Permalink
Call the onExecute directly
Browse files Browse the repository at this point in the history
  • Loading branch information
D4N14L committed May 7, 2022
1 parent 13d0d34 commit 9a54ec2
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ interface IInternalScopedCommandLineParserOptions extends ICommandLineParserOpti
readonly actionOptions: ICommandLineActionOptions;
readonly unscopedActionParameters: ReadonlyArray<CommandLineParameter>;
readonly onDefineScopedParameters: (commandLineParameterProvider: CommandLineParameterProvider) => void;
readonly onExecute: () => Promise<void>;
}

/**
* A CommandLineParser used exclusively to parse the scoped command-line parameters
* for a ScopedCommandLineAction.
*/
class InternalScopedCommandLineParser extends CommandLineParser {
private _internalOptions: IInternalScopedCommandLineParserOptions;

Expand All @@ -40,12 +43,6 @@ class InternalScopedCommandLineParser extends CommandLineParser {
protected onDefineParameters(): void {
// No-op. Parameters are manually defined in the constructor.
}

protected async onExecute(): Promise<void> {
await super.onExecute();
// Redirect action execution to the provided callback
await this._internalOptions.onExecute();
}
}

/**
Expand Down Expand Up @@ -115,8 +112,7 @@ export abstract class ScopedCommandLineAction extends CommandLineAction {
...parserOptions,
actionOptions: this._options,
unscopedActionParameters: this.parameters,
onDefineScopedParameters: this.onDefineScopedParameters.bind(this),
onExecute: this.onExecute.bind(this)
onDefineScopedParameters: this.onDefineScopedParameters.bind(this)
});
}

Expand Down Expand Up @@ -153,6 +149,7 @@ export abstract class ScopedCommandLineAction extends CommandLineAction {

// Call the scoped parser using only the scoped args.
await this._scopedCommandLineParser.executeWithoutErrorHandling(scopedArgs);
await super._execute();
return;
}

Expand Down

0 comments on commit 9a54ec2

Please sign in to comment.