-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmd.js
executable file
·40 lines (32 loc) · 1.13 KB
/
cmd.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
#!/usr/bin/env node
const { toke } = require('./')
const SonicBoom = require('sonic-boom')
const args = require('minimist')(process.argv.slice(2), {
alias: {
h: ['help'],
a: ['ancillary'],
d: ['dest', 'destination'],
k: ['keep']
}
})
if (args.h) {
console.log(require('fs').readFileSync(require('path').join(__dirname, 'usage.txt')) + '')
process.exit(0)
}
let format = args._.join(' ')
let destination
let ancillary
if ((args.d + '').toLowerCase() === 'stdout') args.d = 1
else if ((args.d + '').toLowerCase() === 'stderr') args.d = 2
if ((args.a + '').toLowerCase() === 'stdout') args.a = 1
else if ((args.a + '').toLowerCase() === 'stderr') args.a = 2
if (args.d === 1) destination = process.stdout
else if (args.d === 2) destination = process.stderr
else if (args.d !== undefined) destination = SonicBoom({ dest: parseInt(args.d) })
if (args.a === 1) ancillary = process.stdout
else if (args.a === 2) ancillary = process.stderr
else if (args.a !== undefined) ancillary = SonicBoom({ dest: parseInt(args.a) })
if (args.k) {
format = { format: format, keep: true }
}
process.stdin.pipe(toke(format, destination, ancillary))