UNPKG

2.38 kBTypeScriptView Raw
1import { AlphabetLowercase, AlphabetUppercase } from './alphabet';
2export declare type DefaultContext<T> = {
3 options: IOptionFlag<T>;
4 flags: {
5 [k: string]: string;
6 };
7};
8export declare type Default<T> = T | ((context: DefaultContext<T>) => T);
9export declare type IFlagBase<T, I> = {
10 name: string;
11 char?: AlphabetLowercase | AlphabetUppercase;
12 description?: string;
13 helpLabel?: string;
14 hidden?: boolean;
15 required?: boolean;
16 dependsOn?: string[];
17 exclusive?: string[];
18 /**
19 * also accept an environment variable as input
20 */
21 env?: string;
22 parse(input: I, context: any): T;
23};
24export declare type IBooleanFlag<T> = IFlagBase<T, boolean> & {
25 type: 'boolean';
26 allowNo: boolean;
27 /**
28 * specifying a default of false is the same not specifying a default
29 */
30 default?: Default<boolean>;
31};
32export declare type IOptionFlag<T> = IFlagBase<T, string> & {
33 type: 'option';
34 helpValue?: string;
35 default?: Default<T | undefined>;
36 multiple: boolean;
37 input: string[];
38 options?: string[];
39};
40export declare type Definition<T> = {
41 (options: {
42 multiple: true;
43 } & Partial<IOptionFlag<T[]>>): IOptionFlag<T[]>;
44 (options: ({
45 required: true;
46 } | {
47 default: Default<T>;
48 }) & Partial<IOptionFlag<T>>): IOptionFlag<T>;
49 (options?: Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
50};
51export declare type EnumFlagOptions<T> = Partial<IOptionFlag<T>> & {
52 options: T[];
53};
54export declare type IFlag<T> = IBooleanFlag<T> | IOptionFlag<T>;
55export declare function build<T>(defaults: {
56 parse: IOptionFlag<T>['parse'];
57} & Partial<IOptionFlag<T>>): Definition<T>;
58export declare function build(defaults: Partial<IOptionFlag<string>>): Definition<string>;
59export declare function boolean<T = boolean>(options?: Partial<IBooleanFlag<T>>): IBooleanFlag<T>;
60export declare const integer: Definition<number>;
61export declare function option<T>(options: {
62 parse: IOptionFlag<T>['parse'];
63} & Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
64declare const stringFlag: Definition<string>;
65export { stringFlag as string };
66export declare const defaultFlags: {
67 color: IBooleanFlag<boolean>;
68};
69export declare type Output = {
70 [name: string]: any;
71};
72export declare type Input<T extends Output> = {
73 [P in keyof T]: IFlag<T[P]>;
74};
75
\No newline at end of file