-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
executable file
·102 lines (89 loc) · 3.51 KB
/
cli.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env ts-node
import type {
ImporterOptions,
RepositoryOptions,
ParserOptions,
DataAccessOptions
} from './src/console/lib/generators/GeneratorOptions';
import {
configurator,
generateImporter,
generateRepository,
generateParser,
generateDataAccessModule
} from './src/console';
import { Command } from 'commander';
export class Cli
{
private program: Command;
constructor() {
this.program = new Command;
this.setProgramCommands();
}
parse() {
this.program.parse()
}
setProgramName() {
this.program.name('iceman-cli')
.description('CLI tools for the tarkov iceman bot')
.version(process.env.VERSION_CONSTRAINT ?? 'none')
}
setProgramCommands() {
this.setAppDevelopmentPort()
this.setAppSecretForRouteAuthorization()
this.generateBotDataAccessModule()
this.generateServerLibParserModule()
this.generateServerLibRepositoryModule()
this.generateServerLibImporterModule()
}
generateBotDataAccessModule() {
this.program.command('make:data-access')
.description('Make a bot data access module')
.option('--classname <classname>', 'classname')
.option('--resource <resource>', 'classname')
.option('--title <title>', 'classname')
.option('--export <export>', 'classname')
.action((options: DataAccessOptions) => generateDataAccessModule(options))
}
generateServerLibParserModule() {
this.program.command('make:parser <module>')
.description('Make a parser module')
.option('--classname <classname>', 'Importer classname')
.option('--resource <resource>', 'Importer classname')
.action((module: string, options: ParserOptions) => generateParser({module}, options))
}
generateServerLibRepositoryModule() {
this.program.command('make:repository <module>')
.description('Make a repository module')
.option('--classname <classname>', 'Importer classname')
.option('--key <key>', 'Importer classname')
.option('--collection <collection>', 'Importer classname')
.option('--resource <resource>', 'Importer classname')
.option('--types <types>', 'Importer classname')
.option('--parser <parser>', 'Importer classname')
.action((module: string, options: RepositoryOptions) => generateRepository({module}, options))
}
generateServerLibImporterModule() {
this.program.command('make:importer <module>')
.description('Make an importer module')
.option('--classname <classname>', 'Importer classname')
.option('--key <key>', 'Importer classname')
.option('--collection <collection>', 'Importer classname')
.option('--types <types>', 'Importer classname')
.option('--repository <repository>', 'Importer classname')
.action((module: string, options: ImporterOptions) => generateImporter({module}, options))
}
setAppDevelopmentPort() {
this.program.command('app:port')
.description('Set the port you would like to use to serve the api')
.argument('<port>', 'The port to use')
.action((port: string | number) => configurator.setAppDevelopmentPort(port))
}
setAppSecretForRouteAuthorization() {
this.program.command('app:secret')
.description('Generate an app secret for route authorization')
.action(configurator.setAppSecret.bind(configurator))
}
}
const commander = new Cli;
commander.parse()