From 05efb708d1c75c75363029b3669eb89e9d25039e Mon Sep 17 00:00:00 2001 From: vvo Date: Tue, 14 Jan 2014 15:47:42 +0100 Subject: [PATCH] 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. --- lib/cli/migrate.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/cli/migrate.js b/lib/cli/migrate.js index bb7e2b27..b35652f1 100644 --- a/lib/cli/migrate.js +++ b/lib/cli/migrate.js @@ -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(); -}; \ No newline at end of file + process.exit(statusCode); +}; + +var success = _.partial(exit, 0); +var failure = function(err) { + logError(err); + exit(1); +} \ No newline at end of file