-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·46 lines (42 loc) · 968 Bytes
/
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
#!/usr/bin/env node
var readline = require('readline')
var fs = require('fs')
var rnbw = require('./index')
var blur = 4
var path = ''
if (process.argv.length > 2) {
if (process.argv[2] === '-b') {
if (!isNaN(process.argv[3])) {
blur = process.argv[3]
if (process.argv[4]) {
path = process.argv[4]
}
}
} else {
path = process.argv[2]
}
}
if (!process.stdin.isTTY) {
var data = ''
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
})
rl.on('line', function(line) {
data += line + '\n'
})
rl.on('close', function() {
console.log(rnbw.rainbow(data, Number(blur)))
})
} else {
if (!fs.existsSync(path)) {
console.log('Could not find file specified by that path')
process.exit(1)
} else {
fs.readFile(path, 'utf8', function(err, data) {
if (err) throw err
console.log(rnbw.rainbow(data, Number(blur)))
})
}
}