UNPKG

2.41 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 exactlyOne?: string[];
19 /**
20 * also accept an environment variable as input
21 */
22 env?: string;
23 parse(input: I, context: any): T;
24};
25export declare type IBooleanFlag<T> = IFlagBase<T, boolean> & {
26 type: 'boolean';
27 allowNo: boolean;
28 /**
29 * specifying a default of false is the same not specifying a default
30 */
31 default?: Default<boolean>;
32};
33export declare type IOptionFlag<T> = IFlagBase<T, string> & {
34 type: 'option';
35 helpValue?: string;
36 default?: Default<T | undefined>;
37 multiple: boolean;
38 input: string[];
39 options?: string[];
40};
41export declare type Definition<T> = {
42 (options: {
43 multiple: true;
44 } & Partial<IOptionFlag<T[]>>): IOptionFlag<T[]>;
45 (options: ({
46 required: true;
47 } | {
48 default: Default<T>;
49 }) & Partial<IOptionFlag<T>>): IOptionFlag<T>;
50 (options?: Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
51};
52export declare type EnumFlagOptions<T> = Partial<IOptionFlag<T>> & {
53 options: T[];
54};
55export declare type IFlag<T> = IBooleanFlag<T> | IOptionFlag<T>;
56export declare function build<T>(defaults: {
57 parse: IOptionFlag<T>['parse'];
58} & Partial<IOptionFlag<T>>): Definition<T>;
59export declare function build(defaults: Partial<IOptionFlag<string>>): Definition<string>;
60export declare function boolean<T = boolean>(options?: Partial<IBooleanFlag<T>>): IBooleanFlag<T>;
61export declare const integer: Definition<number>;
62export declare function option<T>(options: {
63 parse: IOptionFlag<T>['parse'];
64} & Partial<IOptionFlag<T>>): IOptionFlag<T | undefined>;
65declare const stringFlag: Definition<string>;
66export { stringFlag as string };
67export declare const defaultFlags: {
68 color: IBooleanFlag<boolean>;
69};
70export declare type Output = {
71 [name: string]: any;
72};
73export declare type Input<T extends Output> = {
74 [P in keyof T]: IFlag<T[P]>;
75};
76
\No newline at end of file