From b830218766b39a5288118719df9a3137acec9468 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 5 Jan 2012 05:49:25 -0500 Subject: [PATCH] [fix] Ensure `forever script.js` works --- lib/forever/cli.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 1e83e973..08b86a7e 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -74,6 +74,19 @@ app.use(flatiron.plugins.cli, { usage: help }); +var actions = [ + 'start', + 'stop', + 'restart', + 'list', + 'config', + 'set', + 'clear', + 'logs', + 'columns', + 'cleanlogs' +]; + var argvOptions = cli.argvOptions = { 'command': {alias: 'c'}, 'errFile': {alias: 'e'}, @@ -453,22 +466,29 @@ app.cmd('help', cli.help = function () { // Remark: this regex matches everything. It has to be added at the end to // make executing other commands possible. // -app.cmd(/(.*)/, cli.start = function () { - var file = require('optimist').argv._[0], +cli.run = function () { + var file = app.argv._[0], options = getOptions(file); + tryStart(file, options, function () { var monitor = forever.start(file, options); monitor.on('start', function () { forever.startServer(monitor); }); }); -}); +}; cli.start = function () { if (app.config.get('help')) { return util.puts(help.join('\n')); } - app.init(app.start); + app.init(function () { + if (actions.indexOf(app.argv._[0]) === -1) { + return cli.run(); + } + + app.start(); + }); };