diff --git a/bin/tend b/bin/tend index 07c23ce..ad3053e 100755 --- a/bin/tend +++ b/bin/tend @@ -1,20 +1,23 @@ #!/usr/bin/env node +var colors = require('colors'); var docopt = require('docopt'); var tend = require('../'); var doc = [ 'Usage:', ' tend', + ' tend ', + ' tend [--restart] [--start] [--ignoreHidden] [--filter ] [ ]', ' tend (--help | --version)', - ' tend [--restart] [--start] [--ignoreHidden] [ ] []', '', 'Options:', - ' -h --help Show this help text', - ' -v --version Show tend version information', - ' -r --restart If is still running when there is a change, stop and re-run it', - ' -i --ignoreHidden Ignore changes to files which start with "."', - ' -s --start Run as soon as tend executes', + ' -h --help Show this help text', + ' -v --version Show tend version information', + ' -r --restart If is still running when there is a change, stop and re-run it', + ' -i --ignoreHidden Ignore changes to files which start with "."', + ' -f --filter Use regular expression to filter which files trigger the command', + ' -s --start Run as soon as tend executes', ].join('\r\n'); var args = docopt.docopt(doc, { @@ -24,10 +27,24 @@ var args = docopt.docopt(doc, { var config = tend.parseConfig(); if (!config && !args[''] && !args['']) { - console.error('No .tendrc file found, must run with " "'); + console.error('No .tendrc file found, must run with " "'.red); process.exit(1); } +if (config && args['']) { + var action = args['']; + if (!config[action]) { + console.error(('Action ' + action + ' not found in .tendrc file').red); + process.exit(1); + } + + var newConfig = {}; + newConfig[action] = config[action]; + newConfig[action].runOnce = true; + newConfig[action].start = true; + config = newConfig; +} + if (!config) { config = {}; } @@ -44,7 +61,7 @@ if (args[''] && args['']) { } for (var key in config) { - console.log('Starting listener: ' + key); + console.log(('Starting listener: ' + key).green); var options = config[key]; tend.tend(options.directory, options.command, options); } diff --git a/lib/index.js b/lib/index.js index eeadc56..5b364a9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -46,6 +46,14 @@ module.exports.tend = function(dir, rawCommand, options) { console.log(('Process ' + pid + ' Started').green); }.bind(this); + if(options.start){ + startCommand(); + } + + if(options.runOnce){ + return; + } + watch.watchTree(dir, function(f, curr, prev) { if (curr === null && prev === null) { return; @@ -75,10 +83,6 @@ module.exports.tend = function(dir, rawCommand, options) { clearTimeout(timeout); timeout = setTimeout(startCommand, 300); }); - - if(options.start){ - startCommand(); - } }; module.exports.parseConfig = function() {