-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
75 lines (58 loc) · 1.57 KB
/
types.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Config
export interface ClimpConfig {
commands: Commands;
global?: {
args?: Args;
positionalArgs?: PositionalArgs;
};
}
// Commands
export type Commands = Record<string, Command>;
export interface Command {
func: CommandFunction;
args?: Args;
positionalArgs?: PositionalArgs;
}
export type ArgValue = string | number | boolean;
export type ArgObj = Record<string, ArgValue | ArgValue[]>;
export type CommandFunction = (args: ArgObj) => any;
// Types
export type Type = 'boolean' | 'string' | 'number' | 'cast';
// Args
export type Args = Record<string, Arg>;
export type Arg = BoolArg | SingularArg | FiniteArg | InfiniteArg;
export interface BasicArg {
required?: boolean;
}
// Note that boolean args (or "flags") can't be "required" in the usual sense;
// including it counts as "true", omitting it counts as "false"
export interface BoolArg extends BasicArg {
type: 'boolean';
required?: false;
}
export interface SingularArg extends BasicArg {
type: Exclude<Type, 'boolean'>;
}
export interface FiniteArg extends BasicArg {
types: Type[];
}
export interface InfiniteArg extends BasicArg {
types: Type;
min?: number;
max?: number;
}
export interface PositionalArgs {
required?: PositionalArgsDescriptor;
optional?: PositionalArgsDescriptor;
}
export type PositionalArgsDescriptor = PositionalArg[] | InfinitePositionalArgs;
export type PositionalArg = NamedPositionalArg | Type;
export interface NamedPositionalArg {
name?: string;
type: Type;
}
export interface InfinitePositionalArgs {
types: Type;
min?: number;
max?: number;
}