#!/usr/bin/env node var fs = require('fs'); var minimist = require('minimist'); var path = require('path'); var waitOn = require('../'); var minimistOpts = { string: ['c', 'd', 'i', 't', 'w', 'httpTimeout', 'tcpTimeout'], boolean: ['h', 'l', 'r', 'v'], alias: { c: 'config', d: 'delay', i: 'interval', l: 'log', r: 'reverse', t: 'timeout', v: 'verbose', w: 'window', h: 'help' } }; var argv = minimist(process.argv.slice(2), minimistOpts); if (argv.help || !argv._.length) { // help return fs.createReadStream(__dirname + '/usage.txt') .pipe(process.stdout) .on('close', function () { process.exit(1); }); } var opts = {}; // if a js/json configuration file is provided require it var configFile = argv.config; if (configFile) { opts = require(path.resolve(configFile)); } // add in the resources listed on the command line opts.resources = argv._; // now check for specific options and set those opts = ['delay', 'httpTimeout', 'interval', 'log', 'reverse', 'timeout', 'tcpTimeout', 'verbose', 'window'] .reduce(function (accum, x) { if (argv[x]) { accum[x] = argv[x]; } return accum; }, opts); waitOn(opts, function (err) { if (err) { return errorExit(err); } // success, could just let it exit on its own, however since // rxjs window waits an extra loop before heeding the unsubscribe // we can exit to speed things up process.exit(0); }); function errorExit(err) { if (err.stack) { console.error(err.stack); } else { console.error(String(err)); } process.exit(1); }