-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
Β·49 lines (41 loc) Β· 1.17 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
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const updateNotifier = require('update-notifier')
const chalk = require('chalk')
const ora = require('ora')
const pkg = require('./package.json')
const main = require('./lib')
const print = require('./lib/print')
updateNotifier({ pkg }).notify()
const cli = meow(`
Usage:
sx <words>
Options:
-v, --version Output version number (v${pkg.version} now)
-h, --help Output usage information
`, {
alias: {
h: 'help',
v: 'version'
}
})
const word = cli.input.join(' ')
if (!word) cli.showHelp()
const spinner = ora('Loading...').start()
main(word)
.then(rst => {
spinner.stop()
if (rst && rst.results && rst.results.result) {
print(rst.results.result)
} else {
console.log(chalk.red('We couldn\'t find any results for your search.'))
console.log('Or you can search it online: ' + chalk.gray.underline(`http://www.abbreviations.com/abbreviation/${encodeURIComponent(word)}`))
}
})
.catch(e => {
spinner.stop()
process.env.NODE_ENV !== 'development'
? console.log(chalk.red('Ah, it seems to be something wrong.'))
: console.error(e.stack)
})