UNPKG

@deepkit/app

Version:

Deepkit App, CLI framework and service container

59 lines (58 loc) 2.49 kB
import { ClassType, TypeAnnotation } from '@deepkit/core'; import { ClassDecoratorResult } from '@deepkit/type'; import { EventDispatcher } from '@deepkit/event'; import { InjectorContext, InjectorModule } from '@deepkit/injector'; import { ControllerConfig } from './service-container.js'; import { LoggerInterface } from '@deepkit/logger'; /** * Flag is a command line argument that is prefixed with `--` and can have a value. */ export type Flag<Options extends { char?: string; hidden?: boolean; description?: string; prefix?: string; } = {}> = TypeAnnotation<'cli:flag', Options>; declare class CommandDecoratorDefinition { name: string; description: string; } declare class CommandDecorator { t: CommandDecoratorDefinition; controller(name: string, options?: { description?: string; }): void; } export declare const cli: ClassDecoratorResult<typeof CommandDecorator>; export interface Command { execute(...args: any[]): Promise<number | void> | number | void; } export declare function isCommand(classType: ClassType<Command>): boolean; export declare function getBinFromEnvironment(): string[]; export declare function getArgsFromEnvironment(): string[]; export declare function parseCliArgs(args: string[], aliases?: { [name: string]: string; }): { [name: string]: boolean | string | string[]; }; export interface ParsedCliControllerConfig { controller?: ClassType; callback?: Function; description?: string; name: string; module: InjectorModule; } export declare function parseControllerConfig(config: ControllerConfig): ParsedCliControllerConfig; export type CommandWriter = (...message: any[]) => void; /** * bin: the binary name, e.g. ['node', 'app.ts'] * argv: the arguments, e.g. ['command', '--help'] * writer: a function used to write the output. Defaults to console.log. */ export declare function executeCommand(script: string, argv: string[], eventDispatcher: EventDispatcher, logger: LoggerInterface, injector: InjectorContext, commandsConfigs: ControllerConfig[], writer?: CommandWriter): Promise<number>; export declare function runCommand(config: ParsedCliControllerConfig, argv: string[], injector: InjectorContext, eventDispatcher: EventDispatcher, logger: LoggerInterface): Promise<any>; export {}; export declare type __ΩFlag = any[]; export declare type __ΩCommand = any[]; export declare type __ΩParsedCliControllerConfig = any[]; export declare type __ΩCommandWriter = any[];