UNPKG

create-abi

Version:

Interactive CLI for create Abi.js projects.

133 lines (130 loc) 5.85 kB
import { PositionalOptions, Options } from 'yargs'; type Alias = { shortName: string; longName: string; }; type Example = { command: string; description: string; }; declare class Command { #private; readonly signature: string; readonly description: string; readonly arguments: Map<string, PositionalOptions>; readonly options: Map<string, Options>; readonly examples: Set<Example>; constructor(signature: string, description: string); setArgument(name: string, options: PositionalOptions): this; getArgument(name: string): PositionalOptions | undefined; hasArgument(name: string): boolean; argument(name: string): PositionalOptions | undefined; argument(name: string, options: PositionalOptions): this; setOption(name: string, options: Options): this; getOption(name: string): Options | undefined; hasOption(name: string): boolean; option(name: string): Options | undefined; option(name: string, options: Options): this; addExample(command: string, description: string): this; getExample(commandOrDescription: string): Example | undefined; example(commandOrDescription: string): Example | undefined; example(command: string, description: string): this; getExamples(): Example[]; setUsage(message: string): this; getUsage(): string; usage(): string; usage(message: string): this; } type Definition = { yes?: boolean; no?: boolean; }; declare abstract class Program<T extends Definition, U extends Required<Omit<T, 'it' | 'yes' | 'no'>>> { #private; readonly name: string; readonly version: string; readonly commands: Set<Command>; readonly aliases: Set<Alias>; readonly interactions: Map<string, unknown>; constructor(name: string, version: string); configure(): void; addCommand(signature: string, description: string): Command; getCommand(signatureOrDescription: string): Command | undefined; command(signatureOrDescription: string): Command | undefined; command(signature: string, description: string): Command; getCommands(): Command[]; strict(enabled?: boolean): this; conflict(key: string, value: string): this; interactive(enabled?: boolean): this; useYes(enabled?: boolean): this; useNo(enabled?: boolean): this; addAlias(shortName: string, longName: string): this; getAlias(shortOrLongName: string): Alias | undefined; alias(shortOrLongName: string): Alias | undefined; alias(shortName: string, longName: string): this; getAliases(): Alias[]; abstract execute(input: ReturnType<typeof this.interact> | ReturnType<typeof this.validate>): number | Promise<number>; /** @param argv Pass here process.argv */ run(argv?: string[]): Promise<number>; isIt(): boolean; abstract validate(definition: T): U; intercept(question: string, answer: unknown): this; interact(definition: T): Promise<U>; parse(args: string[]): T; getInteraction(message: string): unknown; setInteraction<T>(question: string, answer: T): this; scanBoolean(definition: T, message: string): Promise<typeof definition.no extends true ? false : typeof definition.yes extends true ? true : undefined>; scanBoolean(definition: T, message: string, initialValue: boolean): Promise<typeof definition.no extends true ? false : typeof definition.yes extends true ? true : boolean>; scanString(message: string): Promise<string | undefined>; scanString(message: string, initialValue: string): Promise<string>; scanChoice<V extends string>(message: string, options: { value: string; label: string; }[]): Promise<V | undefined>; scanChoice<V extends string>(message: string, options: { value: string; label: string; }[], initialValue: V): Promise<V>; panic(message: string): never; cancel(message?: string): void; intro(title?: string): void; outro(message?: string): void; note(message?: string, title?: string): void; spinner(): { start: (msg?: string) => void; stop: (msg?: string, code?: number) => void; message: (msg?: string) => void; }; info(message: string): void; warn(message: string): void; error(message: string): void; step(message: string): void; success(message: string): void; red(output: string | number | boolean): string; green(output: string | number | boolean): string; blue(output: string | number | boolean): string; yellow(output: string | number | boolean): string; magenta(output: string | number | boolean): string; cyan(output: string | number | boolean): string; gray(output: string | number | boolean): string; grey(output: string | number | boolean): string; white(output: string | number | boolean): string; black(output: string | number | boolean): string; bgRed(output: string | number | boolean): string; bgGreen(output: string | number | boolean): string; bgBlue(output: string | number | boolean): string; bgYellow(output: string | number | boolean): string; bgMagenta(output: string | number | boolean): string; bgCyan(output: string | number | boolean): string; bgWhite(output: string | number | boolean): string; bgBlack(output: string | number | boolean): string; reset(output: string | number | boolean): string; dim(output: string | number | boolean): string; bold(output: string | number | boolean): string; italic(output: string | number | boolean): string; underline(output: string | number | boolean): string; inverse(output: string | number | boolean): string; hidden(output: string | number | boolean): string; strikethrough(output: string | number | boolean): string; } export { type Alias, Command, type Definition, type Example, Program };