radashi-helper
Version:
Help with managing your own Radashi
39 lines (31 loc) • 1.52 kB
TypeScript
import { StdioOption } from 'exec';
declare class RadashiError extends Error {
constructor(message: string);
}
declare class EarlyExitError extends RadashiError {
constructor(message?: string);
}
type LogHandler = (type: 'info' | 'warn' | 'error', msg: string, ...args: any[]) => void;
declare function setLogHandler(handler: LogHandler): void;
type OpenFileHandler = (file: string) => Promise<void>;
declare function setFileOpener(handler: OpenFileHandler): void;
type PromptType = 'autocomplete' | 'text' | 'confirm' | 'select';
interface PromptOptions<Type extends PromptType, Value> {
type: Type;
name: string;
message: string;
choices?: PromptChoice<Value>[];
initial?: PromptResult<Type, Value>;
validate?: (value: PromptResult<Type, Value>) => string | true;
}
interface PromptChoice<Value> {
title: string;
value: Value;
description?: string;
}
type PromptResult<Type extends PromptType, Value> = Type extends 'autocomplete' ? Value : Type extends 'text' ? string : Type extends 'confirm' ? boolean : Type extends 'select' ? Value : never;
type PromptHandler = <Type extends PromptType, const Value>(options: PromptOptions<Type, Value>) => Promise<PromptResult<Type, Value> | undefined>;
declare function setPromptHandler(handler: PromptHandler): void;
declare function setStdio(arg: StdioOption): void;
declare function run(argv: string[]): Promise<any>;
export { EarlyExitError, RadashiError, run, setFileOpener, setLogHandler, setPromptHandler, setStdio };