-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·54 lines (43 loc) · 1.03 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
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const chalk = require('chalk')
const getStdin = require('get-stdin')
const { LANGUAGE } = require('./const')
const { translate } = require('.')
const CLI_DEFAULT_TARGET = LANGUAGE.EN
const print = console.log
;(async () => {
const cli = meow(`
Usage
$ fy <text>
$ echo <text> | fy
Options
--target. -t Target language, values can be:
${Object.values(LANGUAGE).join(', ')}
--help, -h Help
Examples
$ fy 腾讯翻译君 --target en
Tencent Mr. Translator
Translation is driven by http://fanyi.qq.com
`, {
flags: {
target: {
type: 'string',
alias: 't',
default: CLI_DEFAULT_TARGET,
},
help: {
alias: 'h',
},
},
})
let original = cli.input.join(' ')
if (!original && !process.stdin.isTTY) {
original = await getStdin()
}
if (!original) {
return cli.showHelp()
}
print(await translate({ target: cli.flags.target, text: original }))
})()