Issue #61 wontfix

Can't specify -c or --config option when using --autogenerate

Matt Wright
created an issue

When trying to run the revision command and using the --autogenerate option, a config file can not be specified with the -c or --config option. For example, the following command:

{{{ alembic revision --config staging.ini --autogenerate -m 'Add some fields' }}}

Produces the following error:

{{{ alembic: error: unrecognized arguments: --config db/development.ini }}}

Comments (1)

  1. Michael Bayer repo owner

    this is a straight argparse configuration, where "-c" is a global option and "revision" is a command; "--autogenerate" is then an option of "revision". This is the recommended method for parsing arguments with Python and Alembic just goes along with best practice recommendations. You can see what it's doing as follows:

    Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import argparse
    >>> parser = argparse.ArgumentParser()
    >>> parser.add_argument("-c", "--config", type=str)
    _StoreAction(option_strings=['-c', '--config'], dest='config', nargs=None, const=None, default=None, type=<type 'str'>, choices=None, help=None, metavar=None)
    >>> subp = parser.add_subparsers()
    >>> cmd1 = subp.add_parser("revision")
    >>> cmd1.add_argument("--autogenerate", action="store_true")
    _StoreTrueAction(option_strings=['--autogenerate'], dest='autogenerate', nargs=0, const=True, default=False, type=None, choices=None, help=None, metavar=None)
    >>> parser.parse_args(['-c', 'somefile.txt', 'revision', '--autogenerate'])
    Namespace(autogenerate=True, config='somefile.txt')
    >>> parser.parse_args(['revision', '-c', 'somefile.txt', '--autogenerate'])
    usage: [-h] [-c CONFIG] {revision} ...
    : error: unrecognized arguments: -c somefile.txt

    if you think argparse should do a better job with help screens or behavior, this would be for

  2. Log in to comment