export declare type NibAction = (context: IContext) => void; export interface Command { name: string; description?: string; aliases?: string[]; usage?: string; action?: NibAction; subcommands?: Command[]; args?: ArgumentDefinition[]; flags?: FlagDefinition[]; } export interface FlagDefinition { name: string; defaultValue?: string; description: string; } export interface ArgumentDefinition { name: string; required: boolean; usage: string; } export interface NibOptions { commands: Command[]; name: string; version: string; description?: string; preAction?: NibAction; } /** * Simple declarative CLI parser and microruntime. */ export declare class Nib { private options; private rootContext; constructor(options: NibOptions); /** * Kicks off CLI process. Separated from constructor for ease of testing. * @param mockContext optional override IContext, useful for testing */ run(mockContext?: IContext): void; private usage; /** * Runs the CLI process by executing the provided context * @param context IContext specifying flags, args, etc. */ private interpretContext; /** * Recursive function for determining whether a command * should be executed or traversed * @param command * @param context * @param head */ private evaluateCommand; } export interface IContext { argList: string[]; args: { [key: string]: string; }; flags: { [key: string]: string; }; exit: (code: number) => void; writeLine: (string: string) => void; } /** * Data structure for the CLI command data and metadata. This default instance of IContext * is used to run Nib — for testing, a custom IContext can be created for mock data and behavior */ export declare class Context implements IContext { readonly argList: string[]; readonly flags: { [key: string]: string; }; readonly logger?: { log: (...args: any[]) => void; }; readonly mockMode: boolean; args: {}; constructor(argList: string[], flags: { [key: string]: string; }, logger?: { log: (...args: any[]) => void; }, mockMode?: boolean); exit(code: number): void; writeLine(string: string): void; }