|
| 1 | +import { Logger } from '@nestjs/common'; |
| 2 | +import { ModuleRef } from '@nestjs/core'; |
| 3 | +import { Command, CommandRunner, InquirerService, SubCommand } from 'nest-commander'; |
| 4 | +import { LifecycleService } from './lifecycle.service'; |
| 5 | + |
| 6 | +@SubCommand({ name: 'list' }) |
| 7 | +export class LifecycleListCommand extends CommandRunner { |
| 8 | + private readonly logger = new Logger(LifecycleListCommand.name); |
| 9 | + |
| 10 | + public constructor( |
| 11 | + protected moduleRef: ModuleRef, |
| 12 | + private readonly inquirer: InquirerService, |
| 13 | + private readonly lifecycleService: LifecycleService, |
| 14 | + ) { |
| 15 | + super(); |
| 16 | + } |
| 17 | + |
| 18 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 19 | + async run(inputs: string[], options: any): Promise<void> { |
| 20 | + this.logger.log('Starting lifecycle list command ...'); |
| 21 | + |
| 22 | + const lifecycles = await this.lifecycleService.listLifecycleSources(); |
| 23 | + |
| 24 | + Object.entries(lifecycles).forEach(([source, actions]) => { |
| 25 | + this.logger.log(`=== Lifecycle Source: ${source} ===`); |
| 26 | + if (actions && Array.isArray(actions) && actions.length > 0) { |
| 27 | + console.table(actions); |
| 28 | + } else { |
| 29 | + this.logger.warn('No lifecycle actions found.'); |
| 30 | + } |
| 31 | + }); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +@Command({ name: 'lifecycle', arguments: '<task>', subCommands: [LifecycleListCommand] }) |
| 36 | +export class LifecycleCommand extends CommandRunner { |
| 37 | + public constructor(protected moduleRef: ModuleRef) { |
| 38 | + super(); |
| 39 | + } |
| 40 | + |
| 41 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 42 | + async run(inputs: string[], options: any): Promise<void> { } |
| 43 | +} |
0 commit comments