-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
38 lines (29 loc) · 821 Bytes
/
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
import minimist from "minimist";
// Base types
export type Command<CtxType> = {
cmd: string;
args: string[];
ctx: CommandContext<CtxType>;
};
export type CommandContext<CtxType> = CtxType & {
argv: minimist.ParsedArgs;
};
export type Mapper<CtxType> = {
[key: string]: (
c: Command<CtxType>
) => CommandOutput | Promise<CommandOutput>;
help: () => CommandOutput<null>;
};
export type CommandOutput<Output = any> = {
raw: Output;
console: string;
error?: boolean;
};
export type OperatorFunction<Output, CtxType> = (
cmd: Command<CtxType>
) => Promise<Output>;
// Helper types
export type SimpleCommand = Command<{}>;
export type SimpleCommandContext = CommandContext<{}>;
export type SimpleMapper = Mapper<{}>;
export type SimpleOperatorFunction<Output> = OperatorFunction<Output, {}>;