process.exit() with proper statusCode

One thing to take into account when making command lines
is to exit with the proper code so that grunt-tasks works as expected
when failing.
This commit is contained in:
vvo 2014-01-14 15:47:42 +01:00
parent 17fcaf4019
commit 05efb708d1

View File

@ -25,8 +25,8 @@ module.exports = function(commands) {
log.join('\n').cyan);
}
})
.catch(logError)
.finally(exit);
.catch(failure)
.then(success);
};
commands['migrate:latest'].help = 'runs migrations that have not run yet';
@ -39,8 +39,8 @@ module.exports = function(commands) {
}).then(function(filename) {
console.log(('Migration ' + filename + ' created!').green);
})
.catch(logError)
.finally(exit);
.catch(failure)
.then(success);
};
commands['migrate:make'].help = 'generates a new migration';
@ -57,8 +57,8 @@ module.exports = function(commands) {
log.join('\n').cyan);
}
})
.catch(logError)
.finally(exit);
.catch(failure)
.then(success);
};
commands['migrate:rollback'].help = 'rolls back the latest migration group';
@ -70,8 +70,8 @@ module.exports = function(commands) {
.then(function(version) {
console.log('Current Version: '.green + version.blue);
})
.catch(logError)
.finally(exit);
.catch(failure)
.then(success);
};
};
@ -112,9 +112,15 @@ var err = function(msg) {
console.error(msg.red);
};
var exit = function() {
var exit = function(statusCode) {
if (knex && knex.client) {
knex.client.pool.destroy();
}
process.exit();
};
process.exit(statusCode);
};
var success = _.partial(exit, 0);
var failure = function(err) {
logError(err);
exit(1);
}