UNPKG

clivo

Version:
76 lines (72 loc) 2.92 kB
interface ClivoOption { label?: string; letter?: string; name: string; } interface ClivoParams { acceptUnspecifiedOptions?: boolean; args: string[]; equalSignValuesOnly?: boolean; options?: ClivoOption[]; parseFrom?: number; } type ClivoDictionary = Record<string, string[]>; interface ClivoAction { action: () => Promise<void>; label: string; } interface ClivoChoice { label?: string; name: string; } type ClivoWorkflowType = "number" | "options" | "text"; interface ClivoWorkflowStep { choices?: ClivoChoice[]; message: string; type: ClivoWorkflowType; } /** * Parses CLI options into a dictionary. * @param {ClivoParams} params - The parameters for parsing options. * @returns {ClivoDictionary} - The parsed options as a dictionary. */ declare function parseCli(params: ClivoParams): ClivoDictionary; /** * Emits an event to listeners. * @param {string} event - The event to emit. * @param {(...args: unknown[]) => void} listener - The listener to call when the event is emitted. */ declare function listenClivoEvent(event: string, listener: (...args: unknown[]) => void): void; /** * Prompts the user to select an option from a list of choices. * @param {string} message - The message to display to the user. * @param {ClivoChoice[]} choices - The list of choices to present to the user. * @returns {Promise<ClivoChoice>} The selected choice. */ declare function promptOptions(message: string, choices: ClivoChoice[]): Promise<ClivoChoice>; /** * Prompts the user to input text. * @param {string} message - The message to display to the user. * @returns {Promise<string>} The input text. */ declare function promptText(message: string): Promise<string>; /** * Prompts the user to input a number. * @param {string} message - The message to display to the user. * @returns {Promise<number>} The input number. */ declare function promptNumber(message: string): Promise<number>; /** * Handles complex workflows with menus and multiple input types. * @param {string} message - The message to display to the user. * @param {Array<ClivoWorkflowStep>} workflow - The workflow to execute. * @returns {Promise<(ClivoChoice | number | string)[]>} The results of the workflow. */ declare function promptWorkflow(message: string, workflow: ClivoWorkflowStep[]): Promise<(ClivoChoice | number | string)[]>; /** * Handles nested menus with dynamic options. * @param {string} message - The message to display to the user. * @param {Array<ClivoAction>} menu - The menu options and their corresponding actions. */ declare function promptMenu(message: string, menu: ClivoAction[]): Promise<void>; export { type ClivoAction, type ClivoChoice, type ClivoDictionary, type ClivoOption, type ClivoParams, type ClivoWorkflowStep, type ClivoWorkflowType, listenClivoEvent, parseCli, promptMenu, promptNumber, promptOptions, promptText, promptWorkflow };