Skip to content

Commit

Permalink
remove process.exit when no callback passed and remove optimist help …
Browse files Browse the repository at this point in the history
…when in module mode

Fixes #516
  • Loading branch information
wzrdtales committed Nov 18, 2017
1 parent 4de822b commit 18a0032
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function dbmigrate (plugins, isModule, options, callback) {
onComplete: onComplete,
migrationProtocol: 1
};
if (typeof isModule !== 'function') {
this.internals.isModule = isModule;
}
var internals = this.internals;

this.internals.plugins = load('fn/plugin')(plugins);
Expand Down
19 changes: 15 additions & 4 deletions lib/commands/create-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ function executeCreateMigration (internals, config, callback) {

if (internals.argv._.length === 0) {
log.error("'migrationName' is required.");
optimist.showHelp();
process.exit(1);
if (!internals.isModule) {
optimist.showHelp();
}

if (typeof callback !== 'function') {
process.exit(1);
} else {
return callback(new Error("'migrationName' is required."));
}
}

createMigrationDir(migrationsDir, function (err) {
Expand All @@ -41,7 +48,11 @@ function executeCreateMigration (internals, config, callback) {

if (err) {
log.error('Failed to create migration directory at ', migrationsDir, err);
process.exit(1);
if (typeof callback !== 'function') {
process.exit(1);
} else {
return callback(new Error('Failed to create migration directory.'));
}
}

internals.argv.title = internals.argv._.shift();
Expand Down Expand Up @@ -88,7 +99,7 @@ function executeCreateMigration (internals, config, callback) {
createSqlFiles(internals, config, callback);
} else {
if (typeof callback === 'function') {
callback();
return callback();
}
}
}
Expand Down

0 comments on commit 18a0032

Please sign in to comment.