diff --git a/lib/commands/base_command.ts b/lib/commands/base_command.ts index 14a3b934..90897abe 100644 --- a/lib/commands/base_command.ts +++ b/lib/commands/base_command.ts @@ -1,6 +1,13 @@ import { Command } from "commander"; import { version } from '../../package.json'; +/** + * This is a base class which provides a common interface for all commands. + * This is mostly used for testing purposes. + * + * Commands implementing this class should override the run method and call parseArguments + * at the beginning of the run method. + */ export abstract class BaseCommand { public program: Command; args: string[] | undefined; @@ -12,6 +19,10 @@ export abstract class BaseCommand { abstract run(): void; + /** + * Create sets up the command line program. Implementing classes can add additional options. + * to this.program. + */ create(options?: { exitOverride?: boolean, suppressOutput?: boolean }): Command { const program = new Command(); @@ -20,6 +31,7 @@ export abstract class BaseCommand { program.exitOverride(); // don't exit on error } if (options?.suppressOutput) { + // don't write anything to the console program.configureOutput({ writeOut: () => { }, writeErr: () => { } @@ -31,6 +43,9 @@ export abstract class BaseCommand { return program; } + /** + * This allows us to pass a custom list of strings as arguments to the command during testing. + */ parseArguments() { if (this.args) { // custom arg parsing to be able to inject args for testing