UNPKG

@mail-core/cli

Version:

Инструментарий для написания cli-скриптов

56 lines (55 loc) 2.74 kB
import type { InferredOptionType } from 'yargs'; import type { OptionWithArg } from '../args'; import type { PromiseValue } from 'type-fest'; export declare type InteractiveReturnType<T extends (...rest: any[]) => Promise<InteractiveAnswers<any>>> = PromiseValue<ReturnType<T>>; export declare type InteractiveQuestion = { value: string | boolean | string[]; prefix?: string; suffix?: string; message: string; type?: 'confirm' | 'input' | 'list' | 'checkbox' | 'radio'; choices?: Array<{ name?: string; value: string; }>; when?: (answers: Record<string, unknown>) => boolean; }; export declare type InteractiveQuestionGroup = { [name: string]: InteractiveQuestion | InteractiveQuestionGroup; }; export declare type InteractiveQuestionInferType<T extends InteractiveQuestion | InteractiveQuestionGroup> = T extends InteractiveQuestionGroup ? { [K in keyof T]: InteractiveQuestionInferType<T[K]>; } : (T['value'] extends boolean ? boolean : T['value']); export declare type InteractiveAnswers<T extends InteractiveQuestionGroup> = { [K in keyof T]: InteractiveQuestionInferType<T[K]>; }; export declare type InteractiveToolsInit = { prefix?: string; yes?: boolean; }; export declare const interactiveToolNewLine: { before: boolean; after: boolean; touch(label?: string | undefined): void; }; export declare type RequireConfig = boolean | { demandOption?: boolean; allowEmpty?: boolean; allowDefault?: boolean; }; export declare function createInteractiveTools(init?: InteractiveToolsInit): { interactive: <T extends InteractiveQuestionGroup>(questions: T) => Promise<InteractiveAnswers<T>>; confirm: (msg: string, value: boolean) => Promise<boolean>; input: (msg: string, value: string) => Promise<string>; select: (msg: string, value: string, choices: InteractiveQuestion['choices'], type?: 'list' | 'radio' | 'checkbox') => Promise<string>; require: <O extends OptionWithArg>(option: O, configOrDemandOption?: boolean | { demandOption?: boolean | undefined; allowEmpty?: boolean | undefined; allowDefault?: boolean | undefined; } | undefined) => Promise<NonNullable<InferredOptionType<O>>>; }; export declare type CLITools = ReturnType<typeof createInteractiveTools>; export declare const interactive: <T extends InteractiveQuestionGroup>(questions: T) => Promise<InteractiveAnswers<T>>; export declare const confirm: (msg: string, value: boolean) => Promise<boolean>; export declare const input: (msg: string, value: string) => Promise<string>; export declare const select: (msg: string, value: string, choices: InteractiveQuestion['choices'], type?: 'list' | 'radio' | 'checkbox') => Promise<string>;