-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·53 lines (43 loc) · 1.21 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
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var minimist = require('minimist')
var pumpify = require('pumpify')
var split = require('split2')
var JSONStream = require('JSONStream')
var gff = require('./')
const through2 = require('through2')
var argv = minimist(process.argv.slice(2), {
boolean: ['stdin', 'write'],
alias: {
stdin: 's'
, write: 'w'
}
})
if (argv.help) {
console.log(
'Usage: bionode-gff <options> <gff file [required]> <output file>\n\n' +
'If no output is provided, the result will be printed to stdout\n\n'
)
}
var output = argv._[1] ? fs.createWriteStream(argv._[1]) : process.stdout
var parser = argv.write ? gff.writer() : gff.parser()
var jsonIN = argv.write ? JSONStream.parse() : through2.obj()
var jsonOUT = argv.write ? through2() : JSONStream.stringify(false)
if (argv.stdin) {
process.stdin.setEncoding('utf8')
process.stdin
.pipe(split())
.pipe(jsonIN)
.pipe(parser)
.pipe(jsonOUT)
.pipe(output)
process.stdin.on('end', function () {
parser.end()
})
} else {
gff.read(argv._[0]).pipe(JSONStream.stringify(false)).pipe(output)
}
process.stdout.on('error', function (err) {
if (err.code === 'EPIPE') { process.exit(0) }
})