UNPKG

2.13 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 IFlagBase<T, I> = {
9 name: string;
10 char?: AlphabetLowercase | AlphabetUppercase;
11 description?: string;
12 hidden?: boolean;
13 required?: boolean;
14 alsoRequire?: string[];
15 /**
16 * also accept an environment variable as input
17 */
18 env?: string;
19 parse(input: I, context: any): T;
20};
21export declare type IBooleanFlag<T> = IFlagBase<T, boolean> & {
22 type: 'boolean';
23 allowNo: boolean;
24};
25export declare type IOptionFlag<T> = IFlagBase<T, string> & {
26 type: 'option';
27 helpValue?: string;
28 default?: T | ((context: DefaultContext<T>) => T | undefined);
29 multiple: boolean;
30 input: string[];
31 options?: string[];
32};
33export declare type Definition<T> = {
34 (options: {
35 multiple: true;
36 } & Partial<IOptionFlag<T>>): IOptionFlag<T[]>;
37 (options: {
38 required: true;
39 } & Partial<IOptionFlag<T>>): IOptionFlag<T>;
40 (options?: Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
41};
42export declare type EnumFlagOptions<T> = Partial<IOptionFlag<T>> & {
43 options: string[];
44};
45export declare type IFlag<T> = IBooleanFlag<T> | IOptionFlag<T>;
46export declare function build<T>(defaults: {
47 parse: IOptionFlag<T>['parse'];
48} & Partial<IOptionFlag<T>>): Definition<T>;
49export declare function build(defaults: Partial<IOptionFlag<string>>): Definition<string>;
50export declare function boolean<T = boolean>(options?: Partial<IBooleanFlag<T>>): IBooleanFlag<T>;
51export declare const integer: Definition<number>;
52export declare function option<T>(options: {
53 parse: IOptionFlag<T>['parse'];
54} & Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
55declare const stringFlag: Definition<string>;
56export { stringFlag as string };
57export declare const defaultFlags: {
58 color: IBooleanFlag<boolean>;
59};
60export declare type Output = {
61 [name: string]: any;
62};
63export declare type Input<T extends Output> = {
64 [P in keyof T]: IFlag<T[P]>;
65};
66
\No newline at end of file