///
import { EventEmitter } from 'events';
import { ICommandArgument, ICommandOption, IOptionHandler, TOptionFlag } from './command';
import { UI } from './lib';
/**
* Option item specific to the collector
*/
interface ICollectorOption extends ICommandOption {
inherits?: boolean;
_flag?: Flag;
}
/**
* Callback signature for a parsed option value
* @param value value that was collected
*/
export declare type IResolvedOptionListener = (value?: T, name?: string) => void;
export declare type IResolvedHelpListener = (usage: ICollectorSummary) => void;
/**
* flag parser
* @ignore
*/
export declare class Flag {
syntax: TOptionFlag;
defaultValue?: any;
handler?: IOptionHandler;
readonly name: string;
readonly alias: string[];
readonly meta: {
vName: string;
vRequired?: boolean;
bool: boolean;
neg: boolean;
};
constructor(syntax: TOptionFlag, defaultValue?: any, handler?: IOptionHandler);
usage(): string;
}
export declare type TCollectorArg = string | string[];
export interface ICollectorResult {
collector?: Collector;
argv?: string[];
options: {
[key: string]: any;
};
args: TCollectorArg[];
}
export interface ICollectorSummary {
name: string;
path: string[];
desc: string;
options: UI.IOutputGrid;
args: UI.IOutputGrid;
subcommands: ICollectorSummary[];
}
export declare enum CollectorEvent {
HELP = "help",
VERSION = "version",
OPTION = "option",
PARSE = "parse"
}
export declare enum CollectorOpt {
HELP = "help",
VERSION = "version"
}
export declare class Collector extends EventEmitter {
private readonly _options;
private readonly _args;
private readonly _commands;
private readonly _flags;
private readonly _metadata;
private _parent;
private _result;
constructor(name: string, description?: string);
name(): string;
name(name: string): this;
description(): string;
description(desc: string): this;
unknowns(allow: boolean): this;
version(): string;
version(v: string, opt?: ICommandOption): this;
help(opt?: ICommandOption): this;
option(...opts: ICollectorOption[]): this;
argument(...args: ICommandArgument[]): this;
parent(p?: Collector): Collector;
root(): Collector;
isRoot(): boolean;
subcommand(name: string, description?: string): Collector;
isOpt(arg: string): boolean;
usage(): ICollectorSummary;
on(event: CollectorEvent.OPTION, listener: IResolvedOptionListener): this;
on(event: CollectorEvent.VERSION, listener: IResolvedOptionListener): this;
on(event: CollectorEvent.HELP, listener: IResolvedHelpListener): this;
on(event: CollectorEvent.PARSE, listener: (result: ICollectorResult) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
/**
* listener for named option
* @param name
* @param listener
*/
onOption(name: string, listener: IResolvedOptionListener): this;
/**
* alias for help event
* @param listener
*/
onHelp(listener: IResolvedHelpListener): this;
/**
* resolve process arguments into a parsed set of options/args
* @param argv sliced process.argv
*/
resolve(argv: string[]): Promise;
result(): ICollectorResult;
/**
* resolve argument-only and reduce original args to remaining options
* @param args
*/
argShift(args: string[]): string[];
/**
* restructure args such that all opts and values are preceded by the "args"
* @param args
*/
optRight(args: string[]): string[];
/**
* resolve Collector instance and update args
* @param args
*/
protected _sliceInstance(args: string[]): Collector;
protected _inherit(options: ICollectorOption[]): this;
protected _defaults(): this;
protected _verify(): this;
protected _receive(current: string, rest: string[]): void;
/**
* process an --{flag}="{val}" syntax
* @param arg argument
*/
private _flagVal;
/**
* resolves value from option argument
* @param current the present flag
* @param rest remaining args
*/
private _optVal;
private _emitOpt;
private _all;
private _err;
private _meta;
}
export {};