mihawk
Version:
A tiny & simple mock server tool, support json,js,cjs,ts(typescript).
58 lines (57 loc) • 2.02 kB
TypeScript
import prompts from 'prompts';
import type { CliArgs } from '../com-types';
interface GetCliArgsOptions {
logDetail?: boolean;
}
/**
* 获取命令行参数,并解析成对象返回
* @param {string[]} processArgv
* @param {GetCliArgsOptions} options
* @returns {Loosify<T>} 返回参数对象
*/
export declare function getCliArgs<T extends Record<string, any> = any>(processArgv?: string[], options?: GetCliArgsOptions): CliArgs<T>;
/**
* 命令行交互:确认提示
* @param {string} question 问题文案
* @returns {Promise<boolean>} 默认确认?
* @example
* (async()=>{
* const ok = await confirmInCLI('Are you sure?', true);
* console.log(ok ? 'YES' : 'NO');
* })
*/
export declare function confirmInCLI(question: string, defaultYes?: boolean): Promise<boolean>;
/**
* 命令行交互:输入文字
* @param {string} promptTxt
*/
export declare function inputTxtInCLI(promptTxt: string, initial?: string): Promise<string>;
/**
* 命令行交互:输入数字
* @param {string} promptTxt
*/
export declare function inputNumInCLI(promptTxt: string, options?: Partial<{
initial: number;
max: number;
min: number;
}>): Promise<number>;
type SelectValue = string | number | boolean | Date;
/**
* 命令行交互:选择 (优先推荐使用 单选-singleSelectInCli; 多选-multipleSelectInCli;)
* @param {Array<string>} choices
*/
export declare function selectInCli<T extends SelectValue>(promptTxt: string, choices: prompts.Choice[], options?: Partial<{
multiple: boolean;
initial: number;
}>): Promise<T | T[]>;
/**
* 命令行交互:单选
* @param {Array<string>} choices
*/
export declare function singleSelectInCli<T extends SelectValue>(promptTxt: string, choices: prompts.Choice[], initial?: number): Promise<T>;
/**
* 命令行交互:多选
* @param {Array<string>} choices
*/
export declare function multipleSelectInCli<T extends SelectValue>(promptTxt: string, choices: prompts.Choice[], initial?: number): Promise<T[]>;
export {};