forked from pmuellr/kbn-alert-load
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kbn-alert-load.js
executable file
·41 lines (31 loc) · 1.16 KB
/
kbn-alert-load.js
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
#!/usr/bin/env node
'use strict'
/** @typedef { import('./lib/types').CommandHandler } CommandHandler */
const logger = require('./lib/logger')
const { commands } = require('./lib/commands')
const { parseArgs } = require('./lib/parse_args')
module.exports = {
main,
}
/** @type { Map<string, CommandHandler> } */
const CommandMap = new Map()
for (const command of commands) {
CommandMap.set(command.name, command)
}
// @ts-ignore
if (require.main === module) main()
function main() {
const { config, minutes, percentFiring, esUrl, kbUrl, scenario, trafficGenerator, trafficGeneratorId, command, commandArgs } = parseArgs()
logger.debug(`cliArguments: ${JSON.stringify({ config, command, commandArgs })}`)
logger.debug(`using config: ${config}`)
const commandHandler = CommandMap.get(command || 'help')
if (commandHandler == null) {
logger.logErrorAndExit(`command not implemented: "${command}"`)
return
}
try {
commandHandler({ config, minutes, percentFiring, esUrl, kbUrl, scenario, trafficGenerator, trafficGeneratorId }, commandArgs)
} catch (err) {
logger.logErrorAndExit(`error running "${command} ${commandArgs.join(' ')}: ${err}`)
}
}