-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·51 lines (46 loc) · 1.21 KB
/
cli.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
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
const chalk = require('chalk')
const fs = require('fs')
const debug = require('debug')('askmike:cli')
const getip = require('./lib/ip')
const cfgCheck = require('./lib/cfg-check')
const doczGen = require('./lib/docz-gen')
const dispatch = (target, opts) => {
let errors = []
switch (target) {
case 'ip':
const addresses = getip(opts)
console.error(`IP Addresses: \n${addresses.join('\n')}`)
break
case 'cfg-check':
errors = cfgCheck.checkAll(opts)
// No output - command will do its own
break
case 'docz-gen':
errors = doczGen.generate(opts)
// No output - command will do its own
break
default:
console.error("Please provide a command as a parameter, eg 'ip' or 'cfg-check', or 'docz-gen'")
process.exit(1)
break
}
return errors
}
var opts = require('minimist')(process.argv.slice(2))
// console.dir(opts)
const target = opts._[0]
let errors = []
errors = dispatch(target, opts)
// debug('errors', errors)
try {
if (errors.length > 0) {
process.exit(1)
} else {
debug(`${target}: ${chalk.green.inverse('ok')}`)
// process.exit(0)
}
} catch (e) {
console.error('Exception', e)
process.exit(1)
}