-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
72 lines (61 loc) · 1.47 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var url = require('url')
var _ = require('lodash')
var nerfDart = require('nerf-dart')
var nopt = require('nopt')
var rc = require('@greenkeeper/rc')
// Available flags and their type definitions
var types = {
api: String,
help: Boolean,
organization: String,
postpublish: Boolean,
private: Boolean,
slug: String,
version: Boolean,
admin: Boolean,
loglevel: [
'error',
'http',
'info',
'silent',
'silly',
'verbose',
'warn'
]
}
// Flag objects from different sources
// 1. defaults flags
// 2. rcfile flags
// 3. nerfDarted rcfile flags (i.e. scoped by api endpoint)
// 4. cli flags
var defaults = {
api: 'https://api.greenkeeper.io/',
postpublish: true
}
var rcFlags = rc.get()
var cliFlags = nopt(types, {
h: '--help',
usage: '--help',
v: '--version',
s: ['--loglevel', 'silent'],
d: ['--loglevel', 'info'],
dd: ['--loglevel', 'verbose'],
ddd: ['--loglevel', 'silly'],
silent: ['--loglevel', 'silent'],
verbose: ['--loglevel', 'verbose'],
quiet: ['--loglevel', 'warn']
})
var api = url.parse(cliFlags.api || rcFlags.api || defaults.api).format()
var prefix = nerfDart(api)
var nerfDartFlags = _(rcFlags)
.pickBy(function (flag, flagName) {
return flagName.slice(0, prefix.length) === prefix
})
.mapKeys(function (flag, flagName) {
return flagName.replace(prefix, '')
})
.value()
var flags = module.exports = _.assign({}, defaults, rcFlags, nerfDartFlags, cliFlags)
nopt.clean(flags, types)
flags.api = api
flags._rc = rc