File size: 883 Bytes
d8f0e51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
declare const flagSymbol: unique symbol;

declare function arg<T extends arg.Spec>(
	spec: T,
	options?: arg.Options
): arg.Result<T>;

declare namespace arg {
	export function flag<T>(fn: T): T & { [flagSymbol]: true };

	export const COUNT: Handler<number> & { [flagSymbol]: true };

	export type Handler<T = any> = (
		value: string,
		name: string,
		previousValue?: T
	) => T;

	export class ArgError extends Error {
		constructor(message: string, code: string);

		code: string;
	}

	export interface Spec {
		[key: string]: string | Handler | [Handler];
	}

	export type Result<T extends Spec> = { _: string[] } & {
		[K in keyof T]?: T[K] extends Handler
			? ReturnType<T[K]>
			: T[K] extends [Handler]
			? Array<ReturnType<T[K][0]>>
			: never;
	};

	export interface Options {
		argv?: string[];
		permissive?: boolean;
		stopAtPositional?: boolean;
	}
}

export = arg;