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