/// import { AsyncLocalStorage } from 'node:async_hooks'; export declare class CliContext { readonly exec: string; readonly script: string; readonly command: CommandCompose; readonly state: Record; constructor(exec: string, script: string, command: CommandCompose); set(key: any, value: T): T; value(key: any): T | undefined; /** * get command flag/arg value, return default value if not exists * @param name * @returns */ read(name: string): any; /** * get command flag value, return default value if not exists * @param name * @returns */ flag(name: string): any; /** * get command arg value, return default value if not exists * @param name * @returns */ arg(name: string): any; log(message: string, ...arg: any): void; info(message: string): void; error(message: string): void; infof(message: string, ...arg: any): void; json(data: any): void; prompt(question: string): Promise; confirm(question: string): Promise; throw(error: Error): never; } export interface ICliParsedFlag { name: string; value: true | string; } export declare class CliApplication { readonly opts: { asyncLocalStorage?: boolean | AsyncLocalStorage; }; protected asyncLocalStorage?: AsyncLocalStorage; protected commands: ICommand[]; protected _fallback: ICommand | null; readonly middlewares: CliAppMiddleware[]; constructor(opts?: { asyncLocalStorage?: boolean | AsyncLocalStorage; }); command(command: ICommand): void; fallback(command: ICommand): void; find(name: string): ICommand | null; use(fn: CliAppMiddleware): void; handle(): Promise; } export interface ICommand { signature: string; description: string; compose(): CommandCompose; handle(ctx: CliContext): Promise | any; } export declare class CommandCompose { readonly name: string; readonly flags: ICommandFlag[]; readonly args: ICommandArg[]; readonly map: Record; constructor(name: string); /** * only for composing command * @param flags * @returns */ flag(...flags: ICommandFlag[]): this; /** * only for composing command * @param args * @returns */ arg(...args: ICommandArg[]): this; /** * get command param, can be flag or arg * @param name * @returns */ get(name: string): any; /** * get command flag/arg value * @param name * @returns */ value(name: string): any; /** * get command flag/arg value, if not exists return default value * @param name * @returns */ read(name: string): any; } export interface ICommandArg { name: string; default?: T; value?: T; type?: Boolean | Number | String; } export interface ICommandFlag extends ICommandArg { alias?: string; multiple?: boolean; } export interface ICliMiddleware { handle(ctx: any, next: any): Promise; } export type CliMiddlewareCallback = (ctx: any, next: any) => Promise; export type CliAppMiddleware = CliMiddlewareCallback | ICliMiddleware;