import { Collector, IResolvedOptionListener } from './collector'; import { ICommandCtor, ICommandDefinition, ICommandOption } from './command'; import { Log, UI } from './lib'; import { IProjectConfig } from './project'; /** * Callback for an option with value callback */ export interface IProgramOptionCallback extends IResolvedOptionListener { (value: T, helper: { ui: UI.Writer; logger: Log.Logger; }): void; } /** * extend package config */ export interface IProgramOptions extends IProjectConfig { version?: string; } /** * Global program options */ export interface IGlobalOptions { version?: boolean; help?: boolean; } /** * Main program registry */ export declare class Program { private readonly options; root: Collector; private _ui; private _logger; private _rargs; private _done; private _err; private _registry; /** * Create the program executor * @param options program options for command handling */ constructor(options?: IProgramOptions); /** * getter for the resolved configuration */ get config(): IProgramOptions; /** * get the version specified for the program */ get version(): string; /** * Register a command for help context * @param names the command names (hierarchy) to be registered * @param ctor the command implementation constructor */ registerCommandHelp(names: string[], ctor?: ICommandCtor, subcommands?: ICommandDefinition[]): Collector; /** * Register a class as the handler for the root command * @param ctor The root command "default" implementation */ registerRoot(ctor?: ICommandCtor): Collector; /** * register a resolved command by its name and constructor * @param names the command names as registered * @param ctor the instance contstructor * @param subcommands Subcommands of the parent. If zero-length array, * it is assumed subcommands exist so '' will be used */ registerCommand(tree: string[], ctor?: ICommandCtor, subcommands?: ICommandDefinition[]): Collector; /** * Add an option to the main program * @param option option configuration object * @param cb optional callback when value is captured */ globalOption(option: ICommandOption, cb?: IProgramOptionCallback): Program; /** * Add help text to the main program * @param heading Add ui heading * @param body Help text to show * @param raw Flag to output the raw text without formatting */ globalHelp(heading: string, body?: string, raw?: boolean): Program; /** * execute the argv against the registered commands * @param argv argv as passthrough to the command collector * @param path command invocation path */ exec(argv: string[], path?: string[]): Promise; /** * output help text */ help(collector?: Collector): void; private _helpSection; /** * register plugins with the plugin manager */ private _registerPlugins; /** * create a command for the CLI processor * @param tree - command name/syntax tree * @param desc - description for the command * @return A command bound to the main program */ private _command; /** * Apply command constructor annotation metadata to the adapter implementation * @param adapter adapter to which command is bound * @param ctor command constructor */ private _registerMeta; /** * Attach handlers to the adapter from the command implementation * @param adapter A registered command processing adapter * @param ctor The command implementation constructor */ private _attachHandlers; /** * defer callback and assign done * @param cb callback to invoke */ private _deferred; }