diff options
| author | utvk <utvk@users.noreply.github.com> | 2014-07-08 18:49:53 +0200 |
|---|---|---|
| committer | utvk <utvk@users.noreply.github.com> | 2014-07-08 18:49:53 +0200 |
| commit | dff368f4a840ffb6dba66fa8c176472977f79a2e (patch) | |
| tree | 98b397a864c896f226762d2c3a9a3f4d4516ce02 /bin | |
| parent | c5823a6596c2cf64b4c12d88eb84e2bca8a8dabe (diff) | |
Added -o option
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/etatsbasen.js | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/bin/etatsbasen.js b/bin/etatsbasen.js index 9241e10..0960900 100755 --- a/bin/etatsbasen.js +++ b/bin/etatsbasen.js @@ -7,6 +7,8 @@ var pkg = require(path.join(__dirname, '..', 'package.json')); var argv = require('minimist')(process.argv.slice(2)); var etatsbasen = require('etatsbasen'); +var defaultCategories = [12,14,17,18,27,33,38,66,68,76]; + process.bin = process.title = 'etatsbasen'; if (argv.v) { @@ -17,10 +19,28 @@ if (argv.v) { var options = {}; options.filename = argv.f || 'etatsbasen.csv'; -if (argv.c && 'string' === typeof argv.c) { - options.categories = argv.c.split(','); -} else { - options.categories = []; +if (argv.c) { + if (Array.isArray(argv.c)) { + options.categories = argv.c; + } else if ('string' === typeof argv.c) { + if ('all' !== argv.c) { + options.categories = [argv.c]; + } + } else { + options.categories = defaultCategories; + } +} + +if (argv.o) { + if (Array.isArray(argv.o)) { + options.headers = argv.o; + } else if ('string' === typeof argv.o || + 'number' === typeof argv.o) { + options.headers = [argv.o]; + } else { + console.log('Unable to parse -o option(s)'); + process.exit(1); + } } function fileNotFound() { @@ -35,11 +55,13 @@ if (argv.h || fileNotFound()) { 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.' + ' -c [all|[c1,c2,..]] Categories to include (defaults: `' + defaultCategories.join(',') + '`)', + ' -f [file] File to read from (defaults: `etatsbasen.csv`)', + ' -o h1[,h2,h3] Include only these headers in output (id or name)', + ' -v Print version.', + ' -h Write this help.' ].join('\n')); + process.exit(); } |
