import { ICommandOption } from './command'; import { Log } from './lib'; import { IProgramOptionCallback, IProgramOptions, Program } from './program'; /** * extension of main cli config with a working directory provided */ export interface ICLIOptions extends IProgramOptions { baseDir?: string; } /** * The main entrypoint for CLI argv parsing and execution */ export declare class CLI { private options?; logger: Log.Logger; program: Program; private _arity; private _commandPath; /** * Creates a new CLI parser instance * * ```ts * const cli = new CLI({ * baseDir: __dirname, * commandDir: './relative/path/to/my/command/impls', * commandDelim: ':', // use colons instead of spaces to traverse command tree * }); * ``` * @param options configurations or overrides to package.json configuration */ constructor(options?: ICLIOptions); /** * 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 */ addGlobalHelp(heading: string, body?: string, raw?: boolean): CLI; /** * Add global options to the main program * @param option global option configuration object * @param cb parsed option value callback */ addGlobalOption(option: ICommandOption, cb?: IProgramOptionCallback): CLI; /** * Main execution method. * Parse arguments from the command line and run the program. * * ```ts * import { CLI } from '@jib/cli'; * * const parser = new CLI({ * // options * }); * parser.parse(process.argv); * ``` * @param argv raw command line arguments */ parse(argv: string[]): Promise; /** * Manually output help text */ help(): CLI; /** * Resolve configurations and initialize the main program. */ private _initProgram; /** * get the absolute command dir */ private get _commandRoot(); /** * locate command by right recursive argv lookup. * NOTE: CLI strategy precludes aliasing with commander. * @param dir directory where to load * @param args argument list to detect command */ private _locateCommand; /** * Scan a directory for potential command resources * @param dir directory to scan */ private _scanDir; /** * scan a directory for subcommands * @param dir the directory to scan * @param ancestry prior ancestry */ private _scanSubcommands; /** * resolve an exported command from module exports * @param mod a module loaded with require() */ private _extractCommandCtor; /** * Provide command help for the current path * @param dir directory of commands * @param parent parent command list */ private _initHelp; /** * normalize raw arguments into an array of individual components * @param args raw arguments */ private _normalizedArgs; }