### Execute with Nest CLI Source: https://nest-commander.jaymcdoniel.dev/en/execution Use the Nest CLI to build and start the command, passing arguments after the double dash. ```bash nest start --watch -- [args] ``` -------------------------------- ### Execute shell commands via CLI Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Example usage patterns for a command named my-exec. ```bash crun my-exec 'echo Hello World!' # OR crun 'echo Hello World!' # OR crun 'echo Hello World!' --shell zsh # OR crun my-exec 'echo Hello World!' -s zsh ``` -------------------------------- ### Define Plugin Configuration Source: https://nest-commander.jaymcdoniel.dev/en/features/plugins Example of a configuration file structure containing a plugins array with package names or local paths. ```json { "plugins": ["nest-commander-plugin", "./my/local/plugin"] } ``` -------------------------------- ### Install nest-commander Source: https://nest-commander.jaymcdoniel.dev/en/introduction/installation Use your preferred package manager to add nest-commander to your project dependencies. ```bash npm i nest-commander # OR yarn add nest-commander # OR pnpm i nest-commander ``` -------------------------------- ### Install nest-commander-testing Source: https://nest-commander.jaymcdoniel.dev/en/testing/installation Commands to add the testing package as a development dependency using common package managers. ```bash npm i -D nest-commander-testing # OR yarn add -D nest-commander-testing # OR pnpm i -D nest-commander-testing ``` -------------------------------- ### Execute a Command via CLI Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Example of invoking the defined command through the CLI, demonstrating both explicit and default execution modes. ```bash crun my-exec 'echo Hello World!' # OR crun 'echo Hello World!' ``` -------------------------------- ### Configure package.json for CLI distribution Source: https://nest-commander.jaymcdoniel.dev/en/execution Define the bin property in package.json to register the CLI command upon installation. ```json { "name": "crun", "description": "A command line runner using nest-commander", "bin": { "crun": "dist/main.js" }, "scripts": { "build": "nest build" }, "dependencies": { "@nestjs/common": "^7.0.0", "@nestjs/core": "^7.0.0", "nest-commander": "^1.2.0" }, "devDependencies": { "@nestjs/cli": "^7.0.0", "@nestjs/schematics": "^7.0.0", "@nestjs/testing": "^7.0.0", "jest": "^26.0.0", "nest-commander-schematics": "^1.1.0", "nest-commander-testing": "^1.1.0", "typescript": "^4.3.0" } } ``` -------------------------------- ### Install nest-commander-schematics as a devDependency Source: https://nest-commander.jaymcdoniel.dev/en/schematics/installation Use your preferred package manager to add the schematics collection to your project's development dependencies. ```bash npm i -D nest-commander-schematics yarn add -D nest-commander-schematics pnpm i -D nest-commander-schematics ``` -------------------------------- ### Bootstrapping the CLI Application Source: https://nest-commander.jaymcdoniel.dev/en/features/factory Use CommandFactory.run to initialize and execute the application with the root module. ```typescript const bootstrap = async () => { await CommandFactory.run(AppModule); }; bootstrap(); ``` -------------------------------- ### CommandFactory.run Source: https://nest-commander.jaymcdoniel.dev/en/api Static method to initialize and run the command application. ```APIDOC ## CommandFactory.run(rootModule, optionsOrLogger?) ### Description Kicks off the command and manages the Nest application lifecycle. ### Parameters - **rootModule** (Type | DynamicModule) - Required - The module or module metadata required to run the command. - **optionsOrLogger** (CommandFactoryRunOptions | NestLogger) - Optional - Options or a Nest logger instance. ``` -------------------------------- ### Generate and Load Completion Scripts Source: https://nest-commander.jaymcdoniel.dev/en/features/completion Commands to generate completion scripts and configure them for shell startup. ```bash my-cli completion-script ``` ```bash echo "source <(my-cli completion-script)" >> ~/.bashrc ``` ```bash echo "source <(my-cli completion-script)" >> ~/.zshrc ``` ```bash autoload -Uz compinit compinit ``` -------------------------------- ### @Help() Source: https://nest-commander.jaymcdoniel.dev/en/api Method decorator to add custom help text to a command. ```APIDOC ## @Help() ### Description Adds custom help text to a command at a specified position. ### Parameters - **position** ('before' | 'beforeAll' | 'after' | 'afterAll') - Required - The position of the help text. ``` -------------------------------- ### Execute application as a script Source: https://nest-commander.jaymcdoniel.dev/en/execution Run the file directly after adding a shebang and setting executable permissions. ```bash ./dist/main [args] [options] ``` -------------------------------- ### Configure CompletionFactory in main.ts Source: https://nest-commander.jaymcdoniel.dev/en/features/completion Initialize the CLI with completion settings using CommandFactory or register it manually via CompletionFactory. ```typescript import { CommandFactory, CompletionFactory } from 'nest-commander'; import { AppModule } from './app.module'; (async () => { const cliCommand = 'YOUR-CLI-COMMAND'; const cliExecutable = 'YOUR-CLI-EXECUTABLE-PATH'; const app = await CommandFactory.createWithoutRunning(AppModule, { completion: { cmd: cliCommand, fig: true, nativeShell: { executablePath: cliExecutable } } }); // Could be done also by using the `registerCompletionCommand` method under `CompletionFactory` CompletionFactory.registerCompletionCommand(app, { cmd: cliCommand, fig: true, nativeShell: { executablePath: cliExecutable } }); await CommandFactory.runApplication(app); })(); ``` -------------------------------- ### CommandRunner.registerWithSubCommands Source: https://nest-commander.jaymcdoniel.dev/en/api Static method to register command classes and their sub-commands. ```APIDOC ## CommandRunner.registerWithSubCommands(meta?) ### Description Returns a list of the root command class and all sub-command classes set via metadata of @Command() and @SubCommand() decorators. ### Parameters - **meta** (string) - Optional - @Command or @SubCommand decorator identifier. ``` -------------------------------- ### Registering Commands and Questions in AppModule Source: https://nest-commander.jaymcdoniel.dev/en/features/factory Add command and question set classes to the providers array of a module to register them with the application. ```typescript @Module({ providers: [TaskRunner, TaskQuestions] }) export class AppModule {} ``` -------------------------------- ### Generate a question set Source: https://nest-commander.jaymcdoniel.dev/en/schematics/usage Use the question schematic to scaffold a new question set. ```bash nest g -c nest-commander-schematics question ``` -------------------------------- ### CommandTestFactory.createTestingCommand Source: https://nest-commander.jaymcdoniel.dev/en/api Sets up a TestingModuleBuilder for creating a TestingModule, similar to Nest's createTestingModule. ```APIDOC ## CommandTestFactory.createTestingCommand ### Description Sets up a TestingModuleBuilder that can be used with Nest's overrideProvider and compile methods for creating a TestingModule. ### Signature CommandFactory.createTestingCommand(moduleMetadata: CommandModuleMetadata): TestingModuleBuilder ### Parameters - **moduleMetadata** (CommandModuleMetadata) - Required - Nest's module metadata which requires imports to be populated. ``` -------------------------------- ### Run CommandFactory Source: https://nest-commander.jaymcdoniel.dev/en/api Static method to initialize and execute the Nest application command lifecycle. ```typescript CommandFactory.run(rootModule: Type | DynamicModule, optionsOrLogger?: CommandFactoryRunOptions | NestLogger): Promise ``` -------------------------------- ### Execute compiled application with Node Source: https://nest-commander.jaymcdoniel.dev/en/execution Run the compiled JavaScript output using the node runtime. ```bash node ./dist/main [args] [options] ``` -------------------------------- ### @Command() Source: https://nest-commander.jaymcdoniel.dev/en/api Class decorator used to define a CLI command. It sets up the command name, arguments, description, and subcommands. ```APIDOC ## @Command() ### Description Defines a CLI command for the application. This is the primary decorator for creating sub-commands. ### Parameters - **name** (string) - Required - The name of the command. - **arguments** (string) - Optional - The arguments the command takes. Use `<>` for required and `[]` for optional. - **description** (string) - Optional - Description for the --help output. - **argsDescription** (Record) - Optional - Descriptions for each argument. - **options** (CommandOptions) - Optional - Extra options for the commander instance. - **subCommands** (Type) - Optional - Related subcommands. - **aliases** (Array) - Optional - Aliases for the command. ``` -------------------------------- ### Mocking CLI Commands with CommandTestFactory Source: https://nest-commander.jaymcdoniel.dev/en/testing/factory Use CommandTestFactory.createTestingCommand to initialize a testing module and CommandTestFactory.run to execute commands with arguments. ```typescript describe('Task Command', () => { let commandInstance: TestingModule; beforeAll(async () => { commandInstance = await CommandTestFactory.createTestingCommand({ imports: [AppModule] }).compile(); }); it('should call the "run" method', async () => { const spawnSpy = jest.spyOn(childProcess, 'spawn'); await CommandTestFactory.run(commandInstance, ['run', 'echo Hello World!']); expect(spawnSpy).toBeCalledWith(['echo Hello World!', { shell: os.userInfo().shell }]); }); }); ``` -------------------------------- ### Generate a command Source: https://nest-commander.jaymcdoniel.dev/en/schematics/usage Use the command schematic to scaffold a new command, triggering a wizard for configuration. ```bash nest g -c nest-commander-schematics command ``` -------------------------------- ### Fig Completion Integration Commands Source: https://nest-commander.jaymcdoniel.dev/en/features/completion Commands for initializing, generating, building, and publishing Fig autocomplete specifications. ```bash npx @withfig/autocomplete-tools init npm --prefix ./.fig/autocomplete run create-spec ``` ```bash my-cli generate-fig-spec > ./.fig/autocomplete/src/.ts ``` ```bash npm --prefix ./.fig/autocomplete run build ``` ```bash . ├── .fig │ └── autocomplete │ ├── build │ │ └── .js │ └── src │ └── .ts └── - same name as ``` ```bash ./ ``` ```bash npm --prefix ./.fig/autocomplete run publish-spec ``` -------------------------------- ### Create a testing command module Source: https://nest-commander.jaymcdoniel.dev/en/api Initializes a TestingModuleBuilder for command testing, similar to Nest's createTestingModule. ```typescript CommandFactory.createTestingCommand(moduleMetadata: CommandModuleMetadata): TestingModuleBuilder ``` -------------------------------- ### Command schematic options Source: https://nest-commander.jaymcdoniel.dev/en/schematics/usage Available flags for customizing the command generation process. ```text --name= Command name. --path= The path to create the service. --sourceRoot= NestJS service source root directory. --flat Whether or not a directory is created. (default: false) --spec Whether or not a spec file is generated. (default: true) --default Whether or not the command is the default command for the CLI. (default: false) --question= The name of the related question set. ``` -------------------------------- ### CommandTestFactory.run Source: https://nest-commander.jaymcdoniel.dev/en/api Executes a command within a test instance. ```APIDOC ## CommandTestFactory.run ### Description Similar to CommandFactory.run but to be used within a test instance. ### Signature CommandTestFactory.run(app: TestingModule, args?: string[]): Promise ### Parameters - **app** (TestingModule) - Required - The testing application to be used for the CommandFactory. - **args** (Array) - Optional - The name of the command to run and options passed as separate array entries. ``` -------------------------------- ### Implement a TaskRunner Command Source: https://nest-commander.jaymcdoniel.dev/en/features/commander A basic implementation of a command runner that executes shell tasks. ```typescript import { spawn } from 'child_process'; import { Command, CommandRunner, Option } from 'nest-commander'; import { userInfo } from 'os'; @Command({ name: 'my-exec', arguments: '', options: { isDefault: true } }) export class TaskRunner extends CommandRunner { async run(inputs: string[], options: Record): Promise { const echo = spawn(inputs[0], { shell: options.shell ?? userInfo().shell }); echo.stdout.on('data', (data: Buffer) => { console.log(data.toString()); }); } @Option({ flags: '-s, --shell ', description: 'A different shell to spawn than the default' }) parseShell(val: string) { return val; } } ``` -------------------------------- ### Run a command in a test environment Source: https://nest-commander.jaymcdoniel.dev/en/api Executes a command within a testing module instance, optionally passing command arguments. ```typescript CommandTestFactory.run(app: TestingModule, args?: string[]): Promise ``` -------------------------------- ### CommandFactory.runWithoutClosing Source: https://nest-commander.jaymcdoniel.dev/en/api Static method to run the command without closing the application. ```APIDOC ## CommandFactory.runWithoutClosing(rootModule, optionsOrLogger?) ### Description The same static method as run, but without handling the closing of the Nest application when the command finishes. Useful for file watchers or pollers. ``` -------------------------------- ### @Option() Source: https://nest-commander.jaymcdoniel.dev/en/api Method decorator used to define options for a command. ```APIDOC ## @Option() ### Description Defines extra options for commands defined with @Command(). ### Parameters - **flags** (string) - Required - The flags for the option (e.g., --flag). - **description** (string) - Optional - Description for the --help output. - **defaultValue** (string or boolean) - Optional - Default value for the option. - **required** (boolean) - Optional - Whether the option is required. - **name** (string) - Optional - Internal name for pairing with @OptionChoicesFor(). - **choices** (Array or true) - Optional - Valid choices for the option. ``` -------------------------------- ### Question schematic options Source: https://nest-commander.jaymcdoniel.dev/en/schematics/usage Available flags for customizing the question set generation process. ```text --name= Questions set name. --path= The path to create the service. --sourceRoot= NestJS service source root directory. --flat Whether or not a directory is created. (default: false) --spec Whether or not a spec file is generated. (default: true) ``` -------------------------------- ### CliUtilityService Source: https://nest-commander.jaymcdoniel.dev/en/api Utility methods for parsing CLI input values. ```APIDOC ## CliUtilityService ### parseBoolean(val: string) Helper method to turn a string into a boolean based on true or false values. ### parseInt(val: string, radix?: number) Simple wrapper around Number.parseInt(). ### parseFloat(val: string) Simple wrapper around Number.parseFloat(). ``` -------------------------------- ### CommandTestFactory.setAnswers Source: https://nest-commander.jaymcdoniel.dev/en/api Mocks user input for automated testing. ```APIDOC ## CommandTestFactory.setAnswers ### Description A command to mock the gathering of information from a user, to help with automated testing. ### Signature CommandFactory.setAnswers(value: any | any[]): void ### Parameters - **value** (Array or any) - Required - The answers to be returned from the user's input gathers in InquirerService#ask. ``` -------------------------------- ### Mock user input for testing Source: https://nest-commander.jaymcdoniel.dev/en/api Sets the return values for InquirerService#ask to simulate user interaction during automated tests. ```typescript CommandFactory.setAnswers(value: any | any[]): void ``` -------------------------------- ### Define Plugin Module Source: https://nest-commander.jaymcdoniel.dev/en/features/plugins Wrap the command in a Nest module to be used as the default export for the plugin. ```typescript @Module({ providers: [PluginCommand] }) export class PluginModule {} ``` -------------------------------- ### Define custom help text position Source: https://nest-commander.jaymcdoniel.dev/en/api Use this decorator to specify where custom help text appears relative to the default help output. ```typescript Help(position: 'before' | 'beforeAll' | 'after' | 'afterAll'): MethodDecorator ``` -------------------------------- ### InquirerService ask and prompt methods Source: https://nest-commander.jaymcdoniel.dev/en/api Asynchronous methods to trigger a question set defined by a name and optional pre-existing values. ```typescript ask(name: string, options: Partial | undefined): Promise // The following is just an alias for the above prompt(name: string, options: Partial | undefined): Promise ``` -------------------------------- ### Mocking User Input with setAnswers Source: https://nest-commander.jaymcdoniel.dev/en/testing/factory Use CommandTestFactory.setAnswers to provide mock responses for InquirerService questions during command execution. ```typescript describe('Task Command', () => { let commandInstance: TestingModule; beforeAll(async () => { commandInstance = await CommandTestFactory.createTestingCommand({ imports: [AppModule] }).compile(); }); it('should call the "run" method', async () => { CommandTestFactory.setAnswers(['echo Hello World!']); const spawnSpy = jest.spyOn(childProcess, 'spawn'); await CommandTestFactory.run(commandInstance, ['run']); expect(spawnSpy).toBeCalledWith(['echo Hello World!', { shell: os.userInfo().shell }]); }); }); ``` -------------------------------- ### CommandTestFactory.useDefaultInquirer Source: https://nest-commander.jaymcdoniel.dev/en/api Reverts to the standard Inquirer instance. ```APIDOC ## CommandTestFactory.useDefaultInquirer ### Description A method to sub back in the regular Inquirer instance instead of the mock used for testing. ### Signature CommandFactory.useDefaultInquirer(): typeof CommandTestFactory ``` -------------------------------- ### Register Commands with Subcommands Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Using the registerWithSubCommands helper to automatically include nested commands. ```typescript @Module({ providers: [...RunCommand.registerWithSubCommands()] }) export class AppModule {} ``` -------------------------------- ### Create Plugin Command Source: https://nest-commander.jaymcdoniel.dev/en/features/plugins Define a command class using the @Command decorator to be exported by the plugin module. ```typescript @Command({ name: 'plugin' }) export class PluginCommand extends CommandRunner { async run() { console.log('From the plugin!'); } } ``` -------------------------------- ### Define a Command with Name and Arguments Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Use the @Command decorator to specify the command name and required arguments. Setting isDefault to true allows the command to run without explicitly naming it. ```typescript @Command({ name: 'my-exec', arguments: '', options: { isDefault: true } }) export class TaskRunner extends CommandRunner { async run(inputs: string[], options: Record): Promise {} } ``` -------------------------------- ### @RootCommand() Source: https://nest-commander.jaymcdoniel.dev/en/api Class decorator used to define the root command of the application. Can only be used once. ```APIDOC ## @RootCommand() ### Description Defines the root command for the application. Similar to @Command() but without a name property. ### Parameters - **arguments** (string) - Optional - The arguments the command takes. - **description** (string) - Optional - Description for the --help output. - **argsDescription** (Record) - Optional - Descriptions for each argument. - **options** (CommandOptions) - Optional - Extra options for the commander instance. - **subCommands** (Type) - Optional - Related subcommands. - **aliases** (Array) - Optional - Aliases for the command. ``` -------------------------------- ### InquirerService.ask Source: https://nest-commander.jaymcdoniel.dev/en/api Asynchronously prompts the user for input based on a predefined question set. ```APIDOC ## ask(name: string, options: Partial | undefined) ### Description Executes a question set defined by the @QuestionSet decorator to collect user input. ### Parameters - **name** (string) - Required - The name of the question set to ask for. - **options** (T or undefined) - Required - Pre-existing options from commander or defined by the developer. Values passed here will not be asked for again. ### Returns - **Promise** - A promise that resolves with the collected user input. ``` -------------------------------- ### Register Commands in AppModule Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Standard registration of command providers in a NestJS module. ```typescript @Module({ providers: [RunCommand, FooCommand] }) export class AppModule {} ``` -------------------------------- ### Implement Variadic Options Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Enable multiple inputs for a single option by using an accumulator pattern in the parser method. ```typescript @Option({ flags: '-c, --options ', description: 'Specify options', }) parseOptions(option: string, optionsAccumulator: string[] = []): string[] { optionsAccumulator.push(option); return optionsAccumulator; } ``` -------------------------------- ### Implement InquirerService in a Command Source: https://nest-commander.jaymcdoniel.dev/en/features/inquirer Inject InquirerService into a CommandRunner to trigger prompts when inputs are missing. ```typescript @Command({ name: 'my-exec', arguments: '[task]', options: { isDefault: true } }) export class TaskRunner extends CommandRunner { constructor(private readonly inquirer: InquirerService) { super(); } async run(inputs: string[], options: Record): Promise { let task = inputs[0]; if (!task) { task = (await this.inquirer.ask<{ task: string }>('task-questions', undefined)).task; } const echo = spawn(task, { shell: options.shell ?? userInfo().shell }); echo.stdout.on('data', (data: Buffer) => { console.log(data.toString()); }); } @Option({ flags: '-s, --shell ', description: 'A different shell to spawn than the default' }) parseShell(val: string) { return val; } } ``` -------------------------------- ### Execute with ts-node Source: https://nest-commander.jaymcdoniel.dev/en/execution Run the TypeScript source directly without manual compilation. ```bash ts-node src/main.ts [args] [options] # OR is ts-node is not installed globally npx|yarn|pnpm ts-node src/main.ts [args] [options] ``` -------------------------------- ### Define a Command Option Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Use the @Option decorator to define flags and a corresponding method to parse the input value. ```typescript @Command({ name: 'my-exec', arguments: '', options: { isDefault: true } }) export class TaskRunner extends CommandRunner { async run(inputs: string[], options: Record): Promise {} @Option({ flags: '-s, --shell ', description: 'A different shell to spawn than the default' }) parseShell(val: string) { return val; } } ``` -------------------------------- ### Define a QuestionSet Source: https://nest-commander.jaymcdoniel.dev/en/features/inquirer Create a class decorated with @QuestionSet to group related questions, using @Question to define individual prompts. ```typescript @QuestionSet({ name: 'task-questions' }) export class TaskQuestions { @Question({ message: 'What task would you like to execute?', name: 'task' }) parseTask(val: string) { return val; } } ``` -------------------------------- ### Inquirer Decorators Source: https://nest-commander.jaymcdoniel.dev/en/api Decorators used to define question sets, individual questions, and dynamic behaviors for prompts. ```APIDOC ## @QuestionSet() Class decorator to register a set of questions. - **name** (string) - Required - Identifier for the question set. ## @Question() Method decorator to define a specific question. - **type** (string) - Optional - Question type (input, number, confirm, list, etc.). Defaults to "input". - **name** (string) - Required - Identifier for the input. - **message** (string) - Required* - The prompt text. - **default** (any) - Optional - Default value. - **choices** (array) - Optional - Options for list/checkbox types. - **validate** (Function) - Optional - Validation logic. - **transform** (Function) - Optional - Input transformation logic. - **when** (Function/boolean) - Optional - Conditional logic for showing the question. ## @ValidateFor(name: string) Method decorator to dynamically define the `validate` logic for a question. ## @TransformFor(name: string) Method decorator to dynamically define the `transform` logic for a question. ## @WhenFor(name: string) Method decorator to dynamically define the `when` logic for a question. ## @MessageFor(name: string) Method decorator to dynamically define the `message` logic for a question. ``` -------------------------------- ### @ChoicesFor(name: string) Source: https://nest-commander.jaymcdoniel.dev/en/api Method decorator to define dynamic choices for an inquirer question. ```APIDOC ## @ChoicesFor(name: string) ### Description Allows a user to define a dynamic value for inquirer’s `choices` option for the named question. The decorated method receives current answer hashes and returns an array of choices. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the question this decorator effects. ``` -------------------------------- ### Define a Subcommand Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Implement a subcommand by using the @SubCommand decorator on a class extending CommandRunner. ```typescript @SubCommand({ name: 'foo', arguments: '[phooey]' }) export class FooCommand extends CommandRunner { // command runner implementation } ``` -------------------------------- ### @OptionChoicesFor() Source: https://nest-commander.jaymcdoniel.dev/en/api Method decorator to dynamically provide choices for an @Option(). ```APIDOC ## @OptionChoicesFor() ### Description Allows dynamic retrieval of choices for an @Option(). The decorated method must return a string array. ### Parameters - **name** (string) - Required - The name matching the @Option() decorator. ``` -------------------------------- ### Export Plugin Module Source: https://nest-commander.jaymcdoniel.dev/en/features/plugins Set the plugin module as the default export for the package. ```typescript import { PluginModule } from './plugin.module'; export default PluginModule; ``` -------------------------------- ### Configure Request-Scoped Providers Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Use the @RequestModule decorator to inject a mock request object, allowing request-scoped providers to function as singletons. ```typescript @RequestModule({ providers: [SimpleCommand, RequestScopedProvider], requestObject: { headers: { Authorization: 'Bearer token' } } }) export class RequestScopedCommandModule {} ``` -------------------------------- ### @DefaultFor(name: string) Source: https://nest-commander.jaymcdoniel.dev/en/api Method decorator to define a dynamic default value for an inquirer question. ```APIDOC ## @DefaultFor(name: string) ### Description Allows a user to define a dynamic value for inquirer’s `default` option for the named question. The decorated method receives the current hash of answers and returns a number, string, or boolean. ### Parameters #### Path Parameters - **name** (string) - Required - The name of the question this decorator effects. ``` -------------------------------- ### Define a Parent Command with Subcommands Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Use the subCommands property in the @Command decorator to register child commands for a parent command. ```typescript @Command({ name: 'my-exec', arguments: '', subCommands: [FooCommand] }) export class RunCommand extends CommandRunner {} ``` -------------------------------- ### Define a module with @RequestModule Source: https://nest-commander.jaymcdoniel.dev/en/api Use this decorator to wrap a Nest module and provide a mock request object for the REQUEST injection token. ```typescript @RequestModule({ providers: [SomeCommand], requestObject: { headers: { Authorization: 'Bearer token' } } }) export class SomeCommandModule {} ``` -------------------------------- ### Revert to default Inquirer Source: https://nest-commander.jaymcdoniel.dev/en/api Restores the standard Inquirer instance, disabling any previously set mock answers. ```typescript CommandFactory.useDefaultInquirer(): typeof CommandTestFactory ``` -------------------------------- ### Set Option Choices Source: https://nest-commander.jaymcdoniel.dev/en/features/commander Restrict option values to a predefined set using the @OptionChoiceFor decorator, which supports dependency injection. ```typescript import { Option, OptionChoiceFor } from 'nest-commander'; @Command({ name: 'my-exec' }) export class RunCommand extends CommandRunner { constructor( private readonly choiceProvider: { getChoicesForRun: () => string[]; } ) { super(); } async run(args: any, options: { runWithColor: 'yes' | 'no' }) { console.log(options); } @Option({ flags: '-c, --color [runWithColor]', name: 'withColor', description: 'Should the command use color in the output' }) parseColorOption(option: string) { return option; } @OptionChoiceFor({ name: 'withColor' }) // make sure this matches the `name` of an `@Options()` decorator getColorChoices() { return this.choiceProvider.getChoicesForRun(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.