UNPKG

piglow-system

Version:

several visualisation utilities for your system

61 lines (46 loc) 1.52 kB
var piglow = require('piglow'); var argv = require('yargs').argv; function binRun(ClientClass, name) { if(argv.v || argv.version) { showVersion(); process.exit(0); } if(argv.h || argv.help) { showHelp(name); process.exit(0); } var options = {}; if(argv.i || argv.interval) options.interval = argv.i || argv.interval; if(argv.b || argv.brightness) options.brightness = argv.b || argv.brightness; if(argv.d || argv.debug) options.debug = argv.d || argv.debug; piglow(function(error, piglowInterface) { if(error) { console.log(error.message); process.exit(1); } var client = new ClientClass(piglowInterface, options); client.start(); process.on('SIGINT', function end() { client.stop(function() { process.exit(); }); }); }); } function showVersion() { console.log(require('../package.json').version); } function showHelp(name) { var help = [ 'Usage: piglow-' + name + ' [options]', '', 'Options:', ' -b, --brightness: the maximum brightness of the LEDs (default: 100)', ' -i, --interval: the refresh interval (default: 1000)', ' -v, --version: the version of piglow-' + name, ' -d, --debug: output debug information', ' -h, --help: this help' ]; console.log(help.join('\n')); } module.exports = binRun;