Skip to content

Commit

Permalink
fix(args): dont parse when called as module
Browse files Browse the repository at this point in the history
fixes #449
  • Loading branch information
wzrdtales committed Aug 13, 2017
1 parent 4238ecd commit ec24db4
Showing 1 changed file with 103 additions and 91 deletions.
194 changes: 103 additions & 91 deletions lib/commands/set-default-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,111 @@ module.exports = function(internals, isModule) {

var rc = require('rc');
var deepExtend = require('deep-extend');
var defaultConfig = {
verbose: false,
table: 'migrations',
'seeds-table': 'seeds',
'force-exit': false,
'sql-file': false,
'non-transactional': false,
config: internals.configFile || internals.cwd + '/database.json',
'migrations-dir': internals.cwd + '/migrations',
'vcseeder-dir': internals.cwd + '/VCSeeder',
'staticseeder-dir': internals.cwd + '/Seeder',
'ignore-completed-migrations': false
};

if(!isModule) {

internals.argv = optimist
.default(defaultConfig)
.usage(
'Usage: db-migrate [up|down|reset|sync|create|db|transition] ' +
'[[dbname/]migrationName|all] [options]'
)
.describe('env',
'The environment to run the migrations under (dev, test, prod).')
.alias('e', 'env')
.string('e')

.describe('migrations-dir', 'The directory containing your migration files.')
.alias('m', 'migrations-dir')
.string('m')

.describe('count', 'Max number of migrations to run.')
.alias('c', 'count')
.string('c')

.describe('dry-run', 'Prints the SQL but doesn\'t run it.')
.boolean('dry-run')

.describe('force-exit', 'Forcibly exit the migration process on completion.')
.boolean('force-exit')

.describe('verbose', 'Verbose mode.')
.alias('v', 'verbose')
.boolean('v')

.alias('h', 'help')
.alias('h', '?')
.boolean('h')

.describe('version', 'Print version info.')
.alias('i', 'version')
.boolean('version')

.describe('config', 'Location of the database.json file.')
.string('config')

.describe('sql-file',
'Automatically create two sql files for up and down statements in ' +
'/sqls and generate the javascript code that loads them.'
)
.boolean('sql-file')

.describe('coffee-file', 'Create a coffeescript migration file')
.boolean('coffee-file')
.describe('ignore-on-init',
'Create files that will run only if ignore-on-init in the env is set ' +
'to false (currently works onlt with SQL)'
).boolean('ignore-on-init')

.describe('migration-table',
'Set the name of the migration table, which stores the migration history.'
)
.alias('table', 'migration-table')
.alias('t', 'table')
.string('t')

.describe('seeds-table',
'Set the name of the seeds table, which stores the seed history.')
.string('seeds-table')

.describe('vcseeder-dir',
'Set the path to the Version Controlled Seeder directory.')
.string('vcseeder-dir')

.describe('staticseeder-dir', 'Set the path to the Seeder directory.')
.string('staticseeder-dir')

.describe('non-transactional', 'Explicitly disable transactions')
.boolean('non-transactional')

.describe('ignore-completed-migrations', 'Start at the first migration')
.boolean('ignore-completed-migrations')

.describe('log-level', 'Set the log-level, for example sql|warn')
.string('log-level');
}
else {

internals.argv = optimist
.default({
verbose: false,
table: 'migrations',
'seeds-table': 'seeds',
'force-exit': false,
'sql-file': false,
'non-transactional': false,
config: internals.configFile || internals.cwd + '/database.json',
'migrations-dir': internals.cwd + '/migrations',
'vcseeder-dir': internals.cwd + '/VCSeeder',
'staticseeder-dir': internals.cwd + '/Seeder',
'ignore-completed-migrations': false
})
.usage(
'Usage: db-migrate [up|down|reset|sync|create|db|transition] ' +
'[[dbname/]migrationName|all] [options]'
)
.describe('env',
'The environment to run the migrations under (dev, test, prod).')
.alias('e', 'env')
.string('e')

.describe('migrations-dir', 'The directory containing your migration files.')
.alias('m', 'migrations-dir')
.string('m')

.describe('count', 'Max number of migrations to run.')
.alias('c', 'count')
.string('c')

.describe('dry-run', 'Prints the SQL but doesn\'t run it.')
.boolean('dry-run')

.describe('force-exit', 'Forcibly exit the migration process on completion.')
.boolean('force-exit')

.describe('verbose', 'Verbose mode.')
.alias('v', 'verbose')
.boolean('v')

.alias('h', 'help')
.alias('h', '?')
.boolean('h')

.describe('version', 'Print version info.')
.alias('i', 'version')
.boolean('version')

.describe('config', 'Location of the database.json file.')
.string('config')

.describe('sql-file',
'Automatically create two sql files for up and down statements in ' +
'/sqls and generate the javascript code that loads them.'
)
.boolean('sql-file')

.describe('coffee-file', 'Create a coffeescript migration file')
.boolean('coffee-file')
.describe('ignore-on-init',
'Create files that will run only if ignore-on-init in the env is set ' +
'to false (currently works onlt with SQL)'
).boolean('ignore-on-init')

.describe('migration-table',
'Set the name of the migration table, which stores the migration history.'
)
.alias('table', 'migration-table')
.alias('t', 'table')
.string('t')

.describe('seeds-table',
'Set the name of the seeds table, which stores the seed history.')
.string('seeds-table')

.describe('vcseeder-dir',
'Set the path to the Version Controlled Seeder directory.')
.string('vcseeder-dir')

.describe('staticseeder-dir', 'Set the path to the Seeder directory.')
.string('staticseeder-dir')

.describe('non-transactional', 'Explicitly disable transactions')
.boolean('non-transactional')

.describe('ignore-completed-migrations', 'Start at the first migration')
.boolean('ignore-completed-migrations')

.describe('log-level', 'Set the log-level, for example sql|warn')
.string('log-level');
internals.argv = {

get argv() {
return defaultConfig;
}
};
}

var plugins = internals.plugins;
var plugin = plugins.hook('init:cli:config:hook');
Expand Down

0 comments on commit ec24db4

Please sign in to comment.