-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgrib-cli.js
35 lines (28 loc) · 959 Bytes
/
grib-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
#!/usr/bin/env node
'use strict';
const program = require('commander');
const fs = require('fs');
const jBinary = require('jbinary');
const grib = require('./index');
program
.version('0.0.1')
.option('-o, --out [optional]','outfile (else stdout)')
.option('-i, --input <requred>','input file (else stdin)')
.option('-p, --pretty','pretty print output json')
.parse(process.argv); // end with parse to parse through the input
console.log("input: " + program.input);
console.log("out: " + program.out);
jBinary.loadData(program.input, function(err, data) {
grib.readData(data, function(err, msgs_) {
if(err) {
console.error(JSON.stringify(err, null, 4));
exit(1);
}
if(program.out) {
fs.writeFileSync(program.out, program.pretty ? JSON.stringify(msgs_, null, 4) : JSON.stringify(msgs_) );
}
else {
console.log(program.pretty ? JSON.stringify(msgs_, null, 4) : JSON.stringify(msgs_));
}
});
});