-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·51 lines (46 loc) · 1.12 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
'use strict'
const meow = require('meow')
const Spin = require('io-spin')
const figures = require('figures')
const chalk = require('chalk')
const update = require('update-notifier')
const main = require('./lib')
const print = require('./lib/print')
const say = require('./lib/say')
const cli = meow(`
Usage:
liyu <words> [options]
Options:
--limit, -l The max definitions you want in each query
--version, -v Output version number
--help, -h Output help (You are here!)
`, {
alias: {
h: 'help',
v: 'version',
l: 'limit'
}
})
update({pkg: cli.pkg}).notify()
const word = cli.input.join(' ')
if (!word) cli.showHelp()
const spin = new Spin('Box1')
spin.start()
say(word)
main(word, cli.flags)
.then(data => {
spin.stop()
if (data.length === 0) {
console.log(
chalk.red(`${figures.cross} There aren't any definitions for ${word} yet.`) +
chalk.dim(`\nCan you define it? ${chalk.underline(`http://www.urbandictionary.com/`)}`)
)
} else {
print(data)
}
})
.catch(e => {
spin.stop()
console.log(e.stack)
})