Skip to content

Commit

Permalink
Fixes for writing help and continuing to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
D4N14L committed May 7, 2022
1 parent 90afc18 commit de2ec50
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libraries/ts-command-line/src/providers/ScopedCommandLineAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ interface IInternalScopedCommandLineParserOptions extends ICommandLineParserOpti
* for a ScopedCommandLineAction.
*/
class InternalScopedCommandLineParser extends CommandLineParser {
private _canExecute: boolean;
private _internalOptions: IInternalScopedCommandLineParserOptions;

public get canExecute(): boolean {
return this._canExecute;
}

public constructor(options: IInternalScopedCommandLineParserOptions) {
// We can run the parser directly because we are not going to use it for any other actions,
// so construct a special options object to make the "--help" text more useful.
Expand All @@ -37,6 +42,7 @@ class InternalScopedCommandLineParser extends CommandLineParser {
};

super(scopedCommandLineParserOptions);
this._canExecute = false;
this._internalOptions = options;
this._internalOptions.onDefineScopedParameters(this);
}
Expand Down Expand Up @@ -148,9 +154,15 @@ export abstract class ScopedCommandLineAction extends CommandLineAction {
scopedArgs.push(...this.remainder.values.slice(1));
}

// Call the scoped parser using only the scoped args.
// Call the scoped parser using only the scoped args to handle parsing
await this._scopedCommandLineParser.executeWithoutErrorHandling(scopedArgs);
await super._execute();

// Only call execute if the parser reached the execute stage. This may not be true if
// the parser exited early due to a specified '--help' parameter.
if (this._scopedCommandLineParser.canExecute) {
await super._execute();
}

return;
}

Expand Down

0 comments on commit de2ec50

Please sign in to comment.