forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-commands.ts
50 lines (41 loc) · 1.14 KB
/
load-commands.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
import { Argv as mriArgv } from 'mri'
import { TypeName } from './util'
type StringArray = ReadonlyArray<string>
export type CommandHandler = (args: mriArgv, argv: StringArray) => void
export { mriArgv }
export interface IOption {
readonly type: TypeName
readonly aliases?: StringArray
readonly description: string
readonly default?: any
}
interface IArgument {
readonly name: string
readonly required: boolean
readonly description: string
readonly type: TypeName
}
export interface ICommandModule {
name?: string
readonly command: string
readonly description: string
readonly handler: CommandHandler
readonly aliases?: StringArray
readonly options?: { [flag: string]: IOption }
readonly args?: ReadonlyArray<IArgument>
readonly unknownOptionHandler?: (flag: string) => void
}
function loadModule(name: string): ICommandModule {
return require(`./commands/${name}.ts`)
}
interface ICommands {
[command: string]: ICommandModule
}
export const commands: ICommands = {}
for (const fileName of __CLI_COMMANDS__) {
const mod = loadModule(fileName)
if (!mod.name) {
mod.name = fileName
}
commands[mod.name] = mod
}