-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
badge-cli.js
executable file
·65 lines (57 loc) · 1.47 KB
/
badge-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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
'use strict'
const { namedColors } = require('./color')
const { makeBadge } = require('./index')
if (process.argv.length < 4) {
console.log('Usage: badge label message [:color] [@style]')
console.log('Or: badge label message color [labelColor] [@style]')
console.log()
console.log(' color, labelColor:')
console.log(` one of ${Object.keys(namedColors).join(', ')}.`)
console.log(' #xxx (three hex digits)')
console.log(' #xxxxxx (six hex digits)')
console.log(' color (CSS color)')
console.log()
console.log('Eg: badge cactus grown :green @flat')
console.log()
process.exit()
}
// Find a format specifier.
let style = ''
for (let i = 4; i < process.argv.length; i++) {
if (process.argv[i][0] === '@') {
style = process.argv[i].slice(1)
process.argv.splice(i, 1)
continue
}
}
const label = process.argv[2]
const message = process.argv[3]
let color = process.argv[4] || ':green'
const labelColor = process.argv[5]
const badgeData = { label, message }
if (style) {
badgeData.style = style
}
if (color[0] === ':') {
color = color.slice(1)
if (namedColors[color] == null) {
// Colorscheme not found.
console.error('Invalid color scheme.')
process.exit(1)
}
badgeData.color = color
} else {
badgeData.color = color
if (labelColor) {
badgeData.labelColor = labelColor
}
}
;(() => {
try {
console.log(makeBadge(badgeData))
} catch (e) {
console.error(e)
process.exit(1)
}
})()