Skip to content

Commit

Permalink
Support multiple -x arguments in Flask-Script interface
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
miguelgrinberg committed Jan 30, 2017
1 parent 0cda0c9 commit 771ef1e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions flask_migrate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ def get_config(self, directory, x_arg=None, opts=None):
config.cmd_opts = argparse.Namespace()
for opt in opts or []:
setattr(config.cmd_opts, opt, True)
if x_arg is not None:
if not getattr(config.cmd_opts, 'x', None):
if not hasattr(config.cmd_opts, 'x'):
if x_arg is not None:
setattr(config.cmd_opts, 'x', [])
if isinstance(x_arg, list) or isinstance(x_arg, tuple):
for x in x_arg:
config.cmd_opts.x.append(x)
else:
config.cmd_opts.x.append(x_arg)
else:
setattr(config.cmd_opts, 'x', None)
return self.call_configure_callbacks(config)


Expand Down Expand Up @@ -233,8 +235,8 @@ def merge(directory=None, revisions='', message=None, branch_label=None,
help=("migration script directory (default is "
"'migrations')"))
@MigrateCommand.option('-x', '--x-arg', dest='x_arg', default=None,
help=("Additional arguments consumed by "
"custom env.py scripts"))
action='append', help=("Additional arguments consumed "
"by custom env.py scripts"))
def upgrade(directory=None, revision='head', sql=False, tag=None, x_arg=None):
"""Upgrade to a later version"""
config = current_app.extensions['migrate'].migrate.get_config(directory,
Expand All @@ -254,8 +256,8 @@ def upgrade(directory=None, revision='head', sql=False, tag=None, x_arg=None):
help=("migration script directory (default is "
"'migrations')"))
@MigrateCommand.option('-x', '--x-arg', dest='x_arg', default=None,
help=("Additional arguments consumed by "
"custom env.py scripts"))
action='append', help=("Additional arguments consumed "
"by custom env.py scripts"))
def downgrade(directory=None, revision='-1', sql=False, tag=None, x_arg=None):
"""Revert to a previous version"""
config = current_app.extensions['migrate'].migrate.get_config(directory,
Expand Down

0 comments on commit 771ef1e

Please sign in to comment.