aboutsummaryrefslogtreecommitdiffstats
path: root/bin/etatsbasen.js
blob: 9241e1029fad6c1acf537a302853d9953bfe7fb9 (plain)
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
54
55
56
57
#!/usr/bin/env node
'use strict';
var path = require('path');
var fs = require('fs');
var pkg = require(path.join(__dirname, '..', 'package.json'));

var argv = require('minimist')(process.argv.slice(2));
var etatsbasen = require('etatsbasen');

process.bin = process.title = 'etatsbasen';

if (argv.v) {
  console.log(pkg.version);
  process.exit();
}

var options = {};
options.filename = argv.f || 'etatsbasen.csv';

if (argv.c && 'string' === typeof argv.c) {
  options.categories = argv.c.split(',');
} else {
  options.categories = [];
}

function fileNotFound() {
  return ! fs.existsSync(options.filename);
}

if (argv.h || fileNotFound()) {
  if (fileNotFound()) {
    console.log(process.title + ': ' + options.filename +
                ': No such file or directory\n');
  }
  console.log([
    'usage: etatsbasen [options]',
    '',
    '  -c [c1,c2,..]   Categories to include',
    '  -f [file]       File to read from (defaults: `etatsbasen.csv`)',
    '  -v              Print version.',
    '  -h              Write this help.'
  ].join('\n'));
  process.exit();
}

var ret = etatsbasen.printCSV(function(err) {
  if (err) {
    throw err;
  }
  }, options);

if (ret) {

} else {
  console.log('Unable to convert');
  process.exit();
}