-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.js
executable file
·67 lines (62 loc) · 1.82 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
var fs = require('fs')
var os = require('os')
var path = require('path')
var jsYaml = require('js-yaml')
var chalk = require('chalk')
var krasivo = require('./krasivo')
var CONFIG_PATH = path.join(os.homedir(), '.krasivorc')
try {
var rawConfig = fs.readFileSync(CONFIG_PATH, 'utf-8')
} catch (_) {
// no config found; do nothing
}
var defaultOptions = {}
if (typeof rawConfig !== 'undefined') {
try {
var config = jsYaml.safeLoad(rawConfig) || {}
} catch (_) {
console.log(chalk.bgRed.bold.white(' ERROR '), chalk.red('.krasivorc is not a valid YAML file'))
process.exit(1)
}
var defaultOptions = config.options || {}
}
if (defaultOptions.shortEmoji === undefined) defaultOptions.shortEmoji = true
require('yargs')
.command('*', 'Communicate prettily', function (yargs) {
yargs
.usage('$0 <string> <foreground> <background>')
.positional('string', {
type: 'string',
describe: 'the string to pretty-print'
})
.positional('foreground', {
type: 'string',
describe: 'the string to fill foreground with'
})
.positional('background', {
type: 'string',
describe: 'the string to fill background with'
})
}, function (argv) {
if (argv._.length !== 3) {
throw new Error('Incorrect number of arguments provided! See `krasivo --help` for help.')
}
console.log(
krasivo.apply(null, Array.prototype.concat.call(argv._, {
shortEmoji: argv.shortEmoji,
skinTone: argv.skinTone
}))
)
})
.option('short-emoji', {
alias: 'e',
default: defaultOptions.shortEmoji,
describe: 'convert emoji names to emoji symbols'
})
.option('skin-tone', {
alias: 's',
default: defaultOptions.skinTone,
describe: 'default skin tone for emoji with skin variations'
})
.argv