add yargs

This commit is contained in:
2025-06-16 23:12:40 +08:00
parent d8c1adf08b
commit b30f9bf7d1
4 changed files with 210 additions and 2 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ import { App, AppConfig, CreateOptions } from '../types';
import { CreateModule } from './utils';
export const app: App = { configure: new Configure() };
export const app: App = { configure: new Configure(), commands: [] };
export const createApp = (options: CreateOptions) => async (): Promise<App> => {
const { config, builder } = options;
+18
View File
@@ -1,6 +1,8 @@
import { ModuleMetadata, PipeTransform, Type } from '@nestjs/common';
import { NestFastifyApplication } from '@nestjs/platform-fastify';
import { CommandModule } from 'yargs';
import { Configure } from '../config/configure';
import { ConfigStorageOption, ConfigureFactory } from '../config/types';
@@ -8,6 +10,8 @@ export type App = {
container?: NestFastifyApplication;
configure: Configure;
commands: CommandModule<RecordAny, RecordAny>[];
};
export interface CreateOptions {
@@ -61,3 +65,17 @@ export interface PanicOption {
exit?: boolean;
}
export interface CommandOption<T = RecordAny, P = RecordAny> extends CommandModule<T, P> {
instant?: boolean;
}
export type CommandItem<T = RecordAny, P = RecordAny> = (
app: Required<App>,
) => Promise<CommandOption<T, P>>;
export type CommandCollection = Array<CommandItem<any, any>>;
export interface CreateOption {
commands: () => CommandCollection;
}