Skip to content

Commit e9c0396

Browse files
committed
feat: Implement lifecycle list command with detailed logging and lifecycle source display
1 parent 41ca4e5 commit e9c0396

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

apps/api/src/management/lifecycle/lifecycle.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ export class LifecycleService extends AbstractServiceSchema implements OnApplica
148148
this.logger.log('LifecycleService bootstraped');
149149
}
150150

151-
public async listLifecycles(): Promise<any> {
152-
const lifecycles = this.lifecycleSources ? Object.keys(this.lifecycleSources) : [];
151+
public listLifecycleSources(): LifecycleSource {
153152
return this.lifecycleSources;
154153
}
155154

0 commit comments

Comments
 (0)