forked from max-mapper/csv-write-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·39 lines (35 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
#!/usr/bin/env node
var ArgumentParser = require('argparse').ArgumentParser
var csv = require('./')
var ndj = require('ndjson')
var packageInfo = require('./package')
argparser = new ArgumentParser({
addHelp: true,
description: packageInfo.description + ' JSON is read from STDIN, formatted' +
' to CSV, and written to STDOUT.',
version: packageInfo.version
})
argparser.addArgument(['--separator'], {
help: "The separator character to use. Defaults to ','.",
defaultValue: ','
})
argparser.addArgument(['--newline'], {
help: "The newline character to use. Defaults to $'\\n'.",
defaultValue: '\n'
})
argparser.addArgument(['--headers'], {
nargs: '+',
help: 'The list of headers to use. If omitted, the keys of the first row ' +
'written to STDIN will be used',
})
argparser.addArgument(['--no-send-headers'], {
action: 'storeFalse',
help: "Don't print the header row.",
defaultValue: true,
dest: 'sendHeaders'
})
args = argparser.parseArgs()
process.stdin
.pipe(ndj.parse())
.pipe(csv(args))
.pipe(process.stdout)