UNPKG

2.15 kBTypeScriptView Raw
1import { AlphabetLowercase, AlphabetUppercase } from './alphabet';
2import { ParserInput } from './parse';
3export interface IFlagBase {
4 name: string;
5 char?: AlphabetLowercase | AlphabetUppercase;
6 description?: string;
7 hidden?: boolean;
8 required?: boolean;
9}
10export interface IBooleanFlag extends IFlagBase {
11 type: 'boolean';
12 allowNo: boolean;
13 value: boolean;
14 input: string;
15}
16export declare type ParseContext = {
17 [k: string]: any;
18};
19export declare type FlagParseContext<T, PC extends ParseContext> = {
20 flag: IOptionFlag<T>;
21 input: ParserInput;
22} & PC;
23export declare type ParseFn<T, PC = any> = (input: string, parseContext: FlagParseContext<T, PC>) => T;
24export interface IOptionFlagBase<T> extends IFlagBase {
25 type: 'option';
26 parse: ParseFn<T>;
27 input: string[];
28}
29export interface IOptionalFlag<T> extends IOptionFlagBase<T> {
30 multiple: false;
31 default?: T | ((context: ParseContext) => T);
32 value?: T;
33}
34export interface IRequiredFlag<T> extends IOptionFlagBase<T> {
35 multiple: false;
36 default?: undefined;
37 value: T;
38}
39export interface IMultiOptionFlag<T> extends IOptionFlagBase<T> {
40 multiple: true;
41 default?: undefined;
42 value: T[];
43}
44export declare type IOptionFlag<T> = IOptionalFlag<T> | IRequiredFlag<T> | IMultiOptionFlag<T>;
45export declare type FlagBuilder<T> = {
46 (options: Partial<IMultiOptionFlag<T>> & {
47 multiple: true;
48 }): IMultiOptionFlag<T>;
49 (options: Partial<IRequiredFlag<T>> & {
50 required: true;
51 }): IRequiredFlag<T>;
52 (options?: Partial<IOptionalFlag<T>>): IOptionalFlag<T>;
53};
54export declare function option<T = string>(defaults?: Partial<IOptionFlag<T>>): FlagBuilder<T>;
55export declare type IFlag<T> = IBooleanFlag | IOptionFlag<T>;
56export declare const flags: {
57 boolean: (options?: Partial<IBooleanFlag>) => IBooleanFlag;
58 integer: FlagBuilder<number>;
59 option: <T = string>(defaults?: Partial<IOptionalFlag<T>> | Partial<IRequiredFlag<T>> | Partial<IMultiOptionFlag<T>>) => FlagBuilder<T>;
60 string: FlagBuilder<string>;
61};
62export declare const defaultFlags: {
63 color: IBooleanFlag;
64};