#1825 - add back official commander and patch it in bin/pm2

This commit is contained in:
Unitech 2015-12-11 15:18:58 +01:00
parent 68b339d526
commit 10b6a67bc0
3 changed files with 40 additions and 4 deletions

38
bin/pm2
View File

@ -189,6 +189,39 @@ function failOnUnknown(fn) {
};
}
/**
* @todo to remove at some point once it's fixed in official commander.js
* https://github.com/tj/commander.js/issues/475
*
* Patch Commander.js Variadic feature
*/
function removeElements(array, args){
var indices = [];
for(var i = 0; i < args.length; i++){
var arg = args[i];
var index = array.indexOf(arg);
while(index > -1){
indices.push(index);
index = array.indexOf(arg, index + 1);
}
}
indices.sort();
for(var i = 0; i < indices.length; i++){
var index = indices[i] - i;
array.splice(index, 1);
}
}
function patchCommanderArg(cmd) {
var argsIndex;
if ((argsIndex = commander.rawArgs.indexOf('--')) >= 0) {
var optargs = commander.rawArgs.slice(argsIndex + 1);
removeElements(cmd, optargs);
}
return cmd;
}
//
// Start command
//
@ -205,6 +238,8 @@ commander.command('start <file|json|stdin|app_name|pm_id...>')
});
}
else {
// Commander.js patch
cmd = patchCommanderArg(cmd);
async.forEachLimit(cmd, 1, function(script, next) {
CLI.start(script, commander, next);
}, function(err) {
@ -258,7 +293,8 @@ commander.command('restart <id|name|all|json|stdin...>')
.option('--watch', 'Toggle watching folder for changes')
.description('restart a process')
.action(function(param) {
// Commander.js patch
param = patchCommanderArg(param);
async.forEachLimit(param, 1, function(script, next) {
CLI.restart(script, next);
}, function(err) {

View File

@ -289,7 +289,7 @@ module.exports = function(God) {
};
/**
* Process to stop on cluster mode
* Procedure to stop a process in cluster mode
*/
if (proc.pm2_env.exec_mode == 'cluster_mode' &&
proc.state != 'disconnected' &&
@ -339,7 +339,7 @@ module.exports = function(God) {
}
else {
/**
* Process to stop on fork mode
* Procedure to stop a process in fork mode
*/
kill_anyway(proc);
}

View File

@ -154,7 +154,7 @@
"chokidar" : "~1.4.0",
"cli-table" : "0.3.1",
"coffee-script" : "~1.10.0",
"commander" : "Unitech/commander.js",
"commander" : "^2.9",
"cron" : "1.1.0",
"debug" : "2.2.0",
"eventemitter2" : "0.4.14",